UNIX时代普遍 [英] Is UNIX time universal

查看:95
本文介绍了UNIX时代普遍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在互联网上做了一些研究,但仍然感到困惑。 UNIX时间是否像GMT / UTC一样普遍,或者是像当地时间一样,因地而异?



我知道UNIX时间是从1970年1月1日开始00 00: 00:00 GMT当我在Java中使用getTime()函数(更具体地说是Date d = new Date(); long currentTime d.getTime())我以几毫秒获得UNIX时间。现在如果人A和人B使用与两个不同时区相同的功能,他们会得到相同的结果吗?

解决方案

现在如果人A和人B使用与两个不同时区相同的功能,他们会得到相同的结果吗?


是的,他们会 - 假设他们的时钟当然是正确的。



java.util.Date 类基本上是从Unix时代起,以毫秒为单位的包装。鉴于Unix纪元在时间上不是即时(不仅仅是1970年1月1日的午夜),所以毫秒数的毫秒数是一样的(忽略相对论和闰秒的讨论)。 ..)



(旁注:在Unix时代,它不是格林威治的午夜,上午1点,因为英国当时正在观察BST。这是英国标准时间,而不是英国夏季时间 - 英国在1968年2月18日至1971年10月31日之间为UTC + 1。对于更多类似的琐事,请参阅 Noda Time用户指南琐事页面


I did some research on internet but still confused. Is UNIX time universal time like GMT/UTC or does it vary from place to place like a local time?

I know UNIX time is counted from 1st Jan, 1970 00:00:00 GMT. When I use getTime() function in Java (more specifically Date d= new Date(); long currentTime d.getTime()) I am getting the UNIX time in milliseconds. Now If person A and person B use the same function who are sitting in two different time zones, will they get the same result?

解决方案

Now If person A and person B use the same function who are sitting in two different time zones, will they get the same result?

Yes, they will - assuming their clocks are both "correct" of course.

The java.util.Date class is basically a wrapper around "the time since the Unix epoch, in milliseconds". Given that the Unix epoch was an instant in time (not just "midnight on January 1st 1970", the number of elapsed milliseconds is the same wherever you are. (Ignoring relativity and any discussion of leap seconds...)

(Side-note: at the Unix epoch, it wasn't midnight in Greenwich. It was 1am, because the UK was observing BST at the time. That's British Standard Time, not British Summer Time - the UK was at UTC+1 from Feb 18th 1968 to October 31st 1971. For more similar trivia, see the Noda Time user guide trivia page.)

这篇关于UNIX时代普遍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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