为什么 Android System.currentTimeMillis() 不是准确的时间戳? [英] Why is Android System.currentTimeMillis() not an accurate Timestamp?

查看:134
本文介绍了为什么 Android System.currentTimeMillis() 不是准确的时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在开发 Android 应用程序时遇到了一个看起来很不寻常的错误.

I've encountered what appears to be a very unusual bug while developing an android application.

我的 MainActivity onCreate 方法中的以下代码:

The following code in my MainActivity onCreate method:

long ts = System.currentTimeMillis();
System.out.println(ts);

返回值为1570469720537.

根据unixtimestamp.com

有人遇到过这个问题吗?任何想法可能导致它?

Has anybody encountered this problem? Any ideas what may be causing it?

推荐答案

虽然纪元时间以秒为单位,System.currentTimeMillis() 返回以毫秒为单位的时间以获得更高的准确性,这是您在例子.如果将其除以 1000,您将获得以秒为单位的时间,它将转换为您期望的当前纪元时间.

While epoch time is measured in seconds, System.currentTimeMillis() returns the time in milliseconds for more accuracy, which is the value you see in the example. If you divide it by 1000 you will get the time in seconds, which will convert to the current epoch time you expect.

您可以在此处粘贴值以查看时间戳:https://www.epochconverter.com/

You can paste the value in here to see the timestamp: https://www.epochconverter.com/

这篇关于为什么 Android System.currentTimeMillis() 不是准确的时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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