I just want to check if time() returns a UTC/GMT timestamp or do I need to use date_default_timezone_set()?
I just want to check if time() returns a UTC/GMT timestamp or do I
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
timereturns a UNIX timestamp, which is timezone independent. Since a UNIX timestamp denotes the seconds since 1970 UTC you could say it’s UTC, but it really has no timezone.To be really clear, a UNIX timestamp is the same value all over the world at any given time. At the time of writing it’s
1296096875in Tokyo, London and New York. To convert this into a “human readable” time, you need to specify which timezone you want to display it in.1296096875in Tokyo is2011-01-27 11:54:35, in London it’s2011-01-27 02:54:35and in New York it’s2011-01-26 21:54:35.In effect you’re usually dealing with (a mix of) these concepts when handling times:
Visualise time like this:
(not to scale)
An absolute point on this line can be expressed as:
Both formats express the same absolute point in time in different notations. The former is a simple counter which started roughly here:
The latter is a much more complicated but equally valid and expressive counter which started roughly here:
UNIX timestamps are simple. They’re a counter which started at one specific point in time and which keeps increasing by 1 every second (for the official definition of what a second is). Imagine someone in London started a stopwatch at midnight Jan 1st 1970, which is still running. That’s more or less what a UNIX timestamp is. Everybody uses the same value of that one stopwatch.
Human readable wall clock time is more complicated, and it’s even more complicated by the fact that it’s abbreviated and parts of it omitted in daily use. 02:54:35 means almost nothing on the timeline pictured above. Jan. 27 2011 02:54:35 is already a lot more specific, but could still mean a variety of different points on this line. “When the clock struck 02:54:35 on Jan. 27 2011 in London, Europe“ is now finally an unambiguous absolute point on this line, because there’s only one point in time at which this was true.
So, timezones are a “modifier” of “wall clock times” which are necessary to express a unique, absolute point in time using a calendar and hour/minute/second notation. Without a timezone a timestamp in such a format is ambiguous, because the clock struck 02:54:35 on Jan. 27 2011 in every country around the globe at different times.
A UNIX timestamp inherently does not have this problem.
To convert from a UNIX timestamp to a human readable wall clock time, you need to specify which timezone you’d like the time displayed in. To convert from wall clock time to a UNIX timestamp, you need to know which timezone that wall clock time is supposed to be in. You either have to include the timezone every single time with each such conversion, or you set the default timezone to be used with
date_default_timezone_set.