确实System.currentTimeMillis的()的返回UTC时间? [英] does System.currentTimeMillis() return UTC time?
问题描述
我想在米利斯当前UTC时间。我搜索谷歌并得到了一些答案,System.currentTimeMillis的()不返回UTC时间。但事实并非如此。如果我下面的:
I want to get the current UTC time in millis. I searched google and got some answers that System.currentTimeMillis() does returns UTC time. but it does not. If I do following:
long t1 = System.currentTimeMillis();
long t2 = new Date().getTime();
long t3 = Calendar.getInstance().getTimeInMillis();
这三个时间几乎相同(不同的是,由于电话毫秒)。
all three times are almost same ( difference is in milli seconds due to calls ).
t1 = 1372060916
t2 = 1372060917
t3 = 1372060918
和这一次是不是UTC时间,而不是这是我的时区的时间。我怎样才能在Android上的当前UTC时间?
and this time is not the UTC time instead this is my timezone time. How can i get the current UTC time in android?
推荐答案
这三种,你已经证明会给自Unix时代,这是一个固定的时间点的毫秒数的线条,不影响当地时区。
All three of the lines you've shown will give the number of milliseconds since the unix epoch, which is a fixed point in time, not affected by your local time zone.
您说:这一次是不是UTC时间 - 我怀疑你实际上已经诊断为不正确。我会建议使用 epochconverter.com 这一点。例如,在你的例子:
You say "this time is not the UTC time" - I suspect you've actually diagnosed that incorrectly. I would suggest using epochconverter.com for this. For example, in your example:
1372060916 = Mon, 24 Jun 2013 08:01:56 GMT
我们不知道你什么时候产生的价值,但除非它是的实际上的在上午8:01 UTC,它与您的系统时钟出现问题。
We don't know when you generated that value, but unless it was actually at 8:01am UTC, it's a problem with your system clock.
无论是 System.currentTimeMillis的
,也没有在日期值
本身受时区。但是,你应该知道,与Date.toString()
的确实的使用本地时区,这会误导很多开发商以为一个日期
本质上是同一个时区相关联 - 它不是,它只是时间上的某个瞬间,没有相关的时区,甚至日历系统
Neither System.currentTimeMillis
nor the value within a Date
itself are affected by time zone. However, you should be aware that Date.toString()
does use the local time zone, which misleads many developers into thinking that a Date
is inherently associated with a time zone - it's not, it's just an instant in time, without an associated time zone or even calendar system.
这篇关于确实System.currentTimeMillis的()的返回UTC时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!