Reputation: 1132
How do I format time using Android's Time Class. I want to display time in this format "hh:mm AM/PM" . I have tried using the Time.format function but I'm not sure if I'm using it correctly.
Thanks
Upvotes: 5
Views: 6506
Reputation: 2073
try:
String strTime = time.format("%I:%M %p");
Your answer can be derived from, but not limited to this link, a C++ reference about "ctime": http://www.cplusplus.com/reference/ctime/strftime/ I found this link to be very helpful deciphering the string formats used in my own work.
The Android.Text.Format.Time.Format docs assumes you know something: Where or how to read "man" page for strftime, which if you weren't familiar using Linux (or a Mac at the terminal) might require some creative web searching or know what "See man strftime for what means what." referred to. Informal as it is in official documentation, it does build off and reference what has already has come before and is left as an exercise for the developer.
Upvotes: 4
Reputation: 163
Time time = new Time();
time.set(0, 0, 17, 4, 5, 1999);
Log.i("Time", time.format("%d.%m.%Y %H:%M:%S"));
Upvotes: 7
Reputation: 16196
Please try this..
SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm aa");
Date dt = new Date();
String strValue = timeFormat.format(dt);
Upvotes: 10