Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Time Class format time

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

like image 313
Mahadevan Sreenivasan Avatar asked Jun 24 '11 07:06

Mahadevan Sreenivasan


2 Answers

Please try this..

SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm aa");
Date dt = new Date();
String strValue = timeFormat.format(dt);
like image 87
Nikhil Avatar answered Oct 28 '22 15:10

Nikhil


Time time = new Time();
time.set(0, 0, 17, 4, 5, 1999);
Log.i("Time", time.format("%d.%m.%Y %H:%M:%S"));
like image 24
Igor Krumpak Avatar answered Oct 28 '22 14:10

Igor Krumpak