47

UNIX timestamp always in GMT?

I tried to run php function time()

and when I tried to convert the unix timestamp from the time() function, the output is not similar to the computer time.

Thank You

bbnn
  • 3,505
  • 10
  • 50
  • 68
  • The value returned from time() is the local time. What are you using to display the value? – Dean Harding May 18 '10 at 01:08
  • 1
    The politically correct time is, of course, UTC, since Greenwich is no longer the centre of the empire. Well, it probably is, but the empire is not as big as it once was :-) – paxdiablo May 18 '10 at 01:17
  • 1
    The value returned from time() is the number of seconds from the epoch date. By itself, it has no timezone. When converted into calendar form, that is when a timezone is applied (or not applied) to the value. – David R Tribble May 18 '10 at 01:22
  • 1
    @Loadmaster, technically it _does_ have a timezone since the UNIX epoch is in UTC. – paxdiablo May 18 '10 at 01:33
  • 1
    @paxdiablo, perhaps, but it's just as logical to say that for a simple count of seconds since an arbitrary epoch start date, there is no concept of timezone, years, days, hours, and so on. It's just a count of time intervals. – David R Tribble May 19 '10 at 19:51

5 Answers5

80

yep, UNIX timestamp represents how much seconds past from unix-time epoch in GMT+0

Naveed Ahmad
  • 6,627
  • 2
  • 58
  • 83
zerkms
  • 249,484
  • 69
  • 436
  • 539
12

Technically, no.

Even though epoch time is the means elapsed seconds since 1/1/70 00:00:00 the real "GMT" (UTC) is not.

UTC time needed to be changed a few times to take in to account the slowing speed of the rotating earth.

As everybody wrote, most people use epoch at UTC.

You can read more in https://en.wikipedia.org/wiki/Unix_time.

Dov Benyomin Sohacheski
  • 7,133
  • 7
  • 38
  • 64
yonatanh
  • 151
  • 2
  • 11
7

UNIX timestamp (A.K.A. Unix's epoch) means elapsed seconds since January 1st 1970 00:00:00 UTC (Universal Time). So , if you need the time in a specific TimeZone, you should convert it.

Even though is technically possible, I would recommend alternative ways to get current time (or any other time), such as getdate that already considers local timezone before returning.

Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
6

Yes, time is supposed to return UTC. If you want that converted to local time, you need a function like, ..., hmm, let me think, .., yes, that's it, localtime :-)

This will give you a more usable form with the individual fields broken out.

Follow those links above for the PHP doc on each. Not sure if PHP has the gmtime equivalent.


And, as an aside, be very careful searching the web for the time manpage with man time - you may not get what you expect. You certainly won't get what you expect if you're looking for the manpage for man itself: man man.

That is, unless you're looking for different things than I was :-)

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
0

Check the return value of date_default_timezone_get() to see what the default time zone is. The link also lists the ways you can change the value, the preferred being by setting date.timezone in php.ini.

ScottR
  • 3,080
  • 3
  • 32
  • 35