Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android get Current UTC time [duplicate]

What is the function to get the current UTC time. I have tried with System.getCurrentTime but i get the current date and time of the device.

Thanks

like image 552
Gerardo Avatar asked May 12 '10 10:05

Gerardo


People also ask

How do I set UTC time zone on Android?

To change to UTC on a standard Android device, tap Settings | System | Date & Time, then turn off the Use-Network Provided Time Zone option, tap the Time Zone and search for Iceland, then tap the back arrow in the upper-left.

What is UTC time now in 24 hour format?

UTC time in ISO-8601 is 09:05:16Z. Note that the Z letter without a space.


1 Answers

System.currentTimeMillis() does give you the number of milliseconds since January 1, 1970 00:00:00 UTC. The reason you see local times might be because you convert a Date instance to a string before using it. You can use DateFormats to convert Dates to Strings in any timezone:

DateFormat df = DateFormat.getTimeInstance(); df.setTimeZone(TimeZone.getTimeZone("gmt")); String gmtTime = df.format(new Date()); 

Also see this related question.

like image 108
Josef Pfleger Avatar answered Oct 14 '22 11:10

Josef Pfleger