如题目所问;UNIX时间戳在每个时区都有变化吗?

例如,如果我向世界另一端的另一个电子邮件发送请求,说“在时间为1397484936时发送电子邮件”,另一个服务器的时间戳会比我自己的时间戳晚12小时吗?


The definition of UNIX timestamp is time zone independent. The UNIX timestamp is the number of seconds (or milliseconds) elapsed since an absolute point in time, midnight of Jan 1 1970 in UTC time. (UTC is Greenwich Mean Time without Daylight Savings time adjustments.) Regardless of your time zone, the UNIX timestamp represents a moment that is the same everywhere. Of course you can convert back and forth to a local time zone representation (time 1397484936 is such-and-such local time in New York, or some other local time in Djakarta) if you want.

如果你想要更长的阅读时间,http://en.wikipedia.org/wiki/Unix_time上的文章非常令人印象深刻。


Unix时间被定义为从协调世界时(UTC) 1970年1月1日星期四00:00:00开始经过的秒数。所以答案是否定的


如果两台计算机都正确设置,并将其时钟设置为正确的时区和UTC值,则它们应该返回相同的值。

当然,这是一个很大的假设。几乎可以肯定,两台计算机报告的时间之间至少有一秒钟的差异,更经常的是几分钟。而且许多计算机的时区设置不正确,当被要求提供时间戳而不是UTC时,会报告本地时间。

这就是理论与实践的区别。理论上都是一样的,实际上你不应该依赖它。


Unix时间戳不会因时区而改变,它们是为了在全球范围内具有标准时间而创建的。

注意:- 时间戳是根据计算机中的当前时间计算的,因此除非您非常确定参与机器中的时间设置,否则不要依赖于它们。


有人说“UTC是没有夏令时调整的格林威治标准时间。”这完全是不真实的。格林尼治标准时间没有夏令时。格林尼治标准时间在英国格林尼治(在Naval Obeservatory)测量[0经度,但不是0纬度]。UTC在赤道(经度为0,纬度为0——恰好位于非洲海岸附近的海洋中)测量。

What difference does it make? It doesn't make a difference in terms of "what time of day is it?" It does, however, make a difference in terms of calculating a year. Now you'd think a year would be measured based upon the location of the center (the core) of the earth, right? When the earth's core is back in the same location it was ~365 days ago, it has been a year. It isn't measured that way. It is measured by a specific location on the earth getting back to the same location (relative to the sun) that it was ~365 days ago. But the period of a day and a year don't divide evenly. Once the earth is back to about where it was a year ago, the earth isn't facing the same direction it was last year, so that spot on the earth isn't facing the same direction it was a year ago. Being further north, Greenwich isn't going to get back to the same spot (relative to the sun) that it was last year at the same time that 0 Lat / 0 Long is. So if you base the definition on Greenwith vs. 0/0, you get a, albeit slightly, different answer to the question "how many days are in a year". To put it another way, when a given spot on the earth gets back to where it was a year ago (relative to the Sun), the core of the earth isn't in the same spot it was a year ago, so what spot you pick matters because the core of the earth is going to be in a different spot (relative to the sun) than it was one year ago, if you pick a different spot on the earth.

UTC和GMT都没有夏令时。格林尼治所处的时区是欧洲/伦敦时间。但格林尼治标准时间没有。GMT是美国人所说的“标准时间”,即没有夏令时。

Getting back to the question, Epoch time doesn't technically have a timezone. It is based on a particular point in time, which just so happens to line up to an "even" UTC time (at the exact beginning of a year and a decade, etc.). If that concept doesn't fit well in your brain, and if it helps to think of Epoch time as being in UTC, go right ahead. You're in good company and in the grand scheme of things, it really doesn't matter. You ever see those law suits where somoene is awarded $1. It's kind of a "you're right, but it doesn't really matter" type of verdict. If someone sued you for saying Epoch time is in the UTC timezone, they would win $1. That wouldn't buy them a cup of coffee at any Starbucks in any timezone on the planet.


不,epoch时间戳不应该改变,因为它有一个固定的时区,即UTC。

如果你想在其他时区使用一个时间对象,只需在你使用的语言库中查找它,但不要试图从epoch时间戳中添加/减去几个小时,并假设它在另一个时区,这会让其他人感到非常困惑,特别是当你在API中公开它时。

如果你使用c++,我推荐这个库。我听说它很快就会被加入标准库。

总的来说,我知道有时时间对象很难处理,在epoch时间戳上添加/子结构看起来更容易。请自己不要去做,也不要劝说别人去做。一旦你习惯了时间对象,你就可以很容易地进行时区转换,而不会因为政治/法律等原因而搞砸历史时区的更改……