views:

178

answers:

4

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

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

zerkms
You're wrong: it's GMT+0! :P
Alix Axel
+3  A: 

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
`time()` considers local timezone as well
zerkms
@zerkms Not according to the documentation: http://php.net/manual/en/function.time.php
Pablo Santa Cruz
yep, my mistake.
zerkms
@Pablo: Had no idea of that, thank you.
Alix Axel
@Alix Axel: No problem! Go Cristiano Ronaldo!
Pablo Santa Cruz
+3  A: 

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

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