安卓得到当前UTC时间 [英] Android get Current UTC time
问题描述
什么是函数来获取当前UTC时间。我曾尝试与System.getCurrentTime但我得到设备的当前日期和时间。
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.
感谢
推荐答案
System.currentTimeMillis的()
确实给你的毫秒数自1970年1月1日00:00 :00 UTC。你看到当地的时间可能是因为您转换日期
实例为字符串,使用它之前的原因。您可以使用日期格式
s要转换日期
s到字符串
S在任何时区:
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 DateFormat
s to convert Date
s to String
s in any timezone:
DateFormat df = DateFormat.getTimeInstance();
df.setTimeZone(TimeZone.getTimeZone("gmt"));
String gmtTime = df.format(new Date());
还有<一个href="http://stackoverflow.com/questions/308683/how-can-i-get-the-current-date-and-time-in-utc-or-gmt-in-java">see此相关的问题。
这篇关于安卓得到当前UTC时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!