获取当前UTC时间的函数是什么?我试过使用System.getCurrentTime,但我得到了设备的当前日期和时间。
谢谢
发布于 2010-05-12 19:35:09
System.currentTimeMillis()
会提供自1970年1月1日00:00:00UTC以来的毫秒数。您看到本地时间的原因可能是因为您在使用Date
实例之前将其转换为字符串。您可以在任何时区使用DateFormat
s将Date
%s转换为String
%s:
DateFormat df = DateFormat.getTimeInstance();
df.setTimeZone(TimeZone.getTimeZone("gmt"));
String gmtTime = df.format(new Date());
https://stackoverflow.com/questions/2818086
复制相似问题