Do unix timestamps change across timezones?

2019-01-08 09:56发布

问题:

As the subject asks; do UNIX timestamps change in each timezone?

For example, if I sent a request to another email the other side of the world saying, "Send out an email when the time is 1397484936", would the other server's timestamp be 12 hours behind my own?

回答1:

The definition of UNIX timestamp is timezone independent. The 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 timezone, a timestamp represents a moment that is the same everywhere. Of course you can convert back and forth to a local timezone representation (time 1397484936 is such-and-such local time in New York, or some other local time in Djakarta) if you want.

The article at http://en.wikipedia.org/wiki/Unix_time is pretty impressive if you'd like a longer read.



回答2:

Unix time is defined as the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970. So the answer is no



回答3:

IF both computers are set up correctly with their clocks set for the correct timezone and UTC values, they should return the same value.
Of course that's a big IF. There's almost certain to be a difference of at least second, more often minutes between the time reported by two computers. And many computers are set up to have incorrect timezone settings, and will report their local time when asked a timestamp rather than UTC.

And in that lies the difference between theory and practice. In theory it's all the same, in practice you should never rely on it.



回答4:

Unix timestamps do not change accross timezones, they are created for the purpose of having a standard time across globe.

NOTE:- Timestamps are calculated on the basis of current time in the computer thus do not rely on them until and unless you are very sure about the time settings in the participating machines.