UNIX timestamp always in GMT?
Asked Answered
Y

5

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

Yeisk answered 18/5, 2010 at 1:0 Comment(5)
The value returned from time() is the local time. What are you using to display the value?Fincher
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 :-)Invagination
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.Bet
@Loadmaster, technically it does have a timezone since the UNIX epoch is in UTC.Invagination
@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.Bet
E
82

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

Epicritic answered 18/5, 2010 at 1:9 Comment(1)
my whole life was a lieReconcile
I
13

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.

Immobility answered 3/9, 2017 at 7:10 Comment(0)
T
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.

Turnpike answered 18/5, 2010 at 1:10 Comment(4)
time() considers local timezone as wellEpicritic
@Epicritic Not according to the documentation: php.net/manual/en/function.time.phpTurnpike
@Alix Axel: No problem! Go Cristiano Ronaldo!Turnpike
GMT not UTC! As mentioned in the documentation: "Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). "Deyo
I
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 :-)

Invagination answered 18/5, 2010 at 1:18 Comment(0)
F
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.

Finecut answered 16/9, 2010 at 18:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.