Want to get time in milliseconds in android Ex 19:57:21:522.How do i do this?Could not find any straight forward API's to do so.
Asked
Active
Viewed 1.5k times
4
-
1Check this http://stackoverflow.com/questions/16516888/how-to-get-current-date-time-in-milliseconds-in-android – Amit Sep 17 '13 at 08:00
-
1http://stackoverflow.com/questions/8826270/how-to-convert-hhmmss-sss-to-milliseconds – Shakeeb Ayaz Sep 17 '13 at 08:06
-
possible duplicate of [Android get current time and date](http://stackoverflow.com/questions/5369682/android-get-current-time-and-date) – Dennis Meng Dec 07 '13 at 21:00
1 Answers
12
Try SimpleDateFormat
http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
Use a pattern with a capital S
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
String currentDateandTime = sdf.format(new Date());

Scary Wombat
- 44,617
- 6
- 35
- 64
-
-
1SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US); specifies the Locale – VMMF May 05 '17 at 16:03