如何在android中获得准确的UTC时间戳 [英] How get accurate UTC timestamp in android

查看:124
本文介绍了如何在android中获得准确的UTC时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道哪个适合获取 UTC 时间

I do not know which one is right for get UTC time

我的代码是

System.currentTimeMillis()

对于java android

for java android

国际的结果是否正确?

也许用户可以更改设备时间,结果会有所不同?(它对 UTC 有影响吗?)

Maybe user can change device time and result be different? (Does it affect on UTC?)

推荐答案

在 Linux 平台上,系统时钟应设置为 UTC.是否真实,是否准确,最终取决于用户.

On Linux platform, the system clock should be set to UTC. Whether it actually is, and whether it is accurate, is ultimately up to the user.

调用 System.currentTimeMillis() 将给出自 1970-01-01T00:00:00Z 以来的 UTC 时间.

Calling System.currentTimeMillis() will give the time in UTC since 1970-01-01T00:00:00Z.

国际的结果是否正确?

是的.前提是时钟与合适的网络时间源同步并且用户没有弄乱它.

Yes. Provided that the clock is synced with a decent network time source and the user hasn't messed with it.

也许用户可以更改设备时间,结果会有所不同?

Maybe user can change device time and result be different?

是的,他们可以.您对此无能为力.

Yes they can. There is not much you can do about it.

您可以尝试连接到网络时间服务器,但用户可能会阻止它,或导致您的游戏连接到虚假时间服务器.如果他们拥有"运行您的游戏的平台,您可能无法获得可靠的时间保证.

You could attempt to connect to a network time server, but the user could block that, or cause your game to connect to a fake time server. If they "own" the platform that your game runs on, you probably have no way to get guaranteed reliable time.

(NTP 上的维基百科页面谈到了中间人攻击.不幸的是,标准 NTP 没有办法解决这个问题.有一个 草案 RFC 用于网络时间安全,但他们自 2015 年以来一直在努力,在撰写本文时仍未完成.)

(The Wikipedia page on NTP talks about man-in-the-middle attacks. Unfortunately, standard NTP doesn't have a way to deal with that. There is a draft RFC for Network Time Security, but they have been working on it since 2015, and it still hadn't concluded at the time of writing.)

这篇关于如何在android中获得准确的UTC时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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