安卓得到当前UTC时间 [英] Android get Current UTC time

查看:772
本文介绍了安卓得到当前UTC时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是函数来获取当前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 DateFormats to convert Dates to Strings 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆