Time format Time Time

How do I format time using Android Time Class. I want to show the time in this format "hh: mm AM / PM". I tried using the Time.format function, but I'm not sure if I use it correctly.

thank

+5
source share
3 answers

Please try this.

SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm aa");
Date dt = new Date();
String strValue = timeFormat.format(dt);
+10
source
Time time = new Time();
time.set(0, 0, 17, 4, 5, 1999);
Log.i("Time", time.format("%d.%m.%Y %H:%M:%S"));
+7
source

:

String strTime = time.format("%I:%M %p");

, , ++ "ctime": http://www.cplusplus.com/reference/ctime/strftime/ , .

Android.Text.Format.Time.Format docs suggests that you know something: Where and how to read the man page for strftime, which, if you are not familiar with Linux (or the Mac on the terminal), may require some creative searching on the Internet or find out that "See man strftime, which means that" .. Unofficially, as in the official documentation, he builds and refers to what was already before, and remains as an exercise for the developer.

+4
source

All Articles