UNIX timestamp always in GMT?

2019-01-14 11:26发布

问题:

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

回答1:

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



回答2:

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.



回答3:

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 :-)



回答4:

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.



回答5:

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.