views:

374

answers:

2

Hi guys, I'm having a bit of trouble with the mktime function. On my production server, if I execute the following:

echo '<p>' . mktime(24, 0,0, 8,29,2009) . ' - 12pm</p>';
echo '<p>' . mktime(23, 0,0, 8,29,2009) . ' - 11pm</p>';
echo '<p>' . mktime(22, 0,0, 8,29,2009) . ' - 10pm</p>';

And then convert those timestamps back to readable format (using www.unixtimestamp.com for quick conversion), the times are all off by one hour. I originally thought this was a problem with 2400 VS 0000, but that wouldn't account for the other dates being off.

Any ideas?

+3  A: 

Your server has a different time zone than you are expecting. Unix timestamps are measured in seconds since 1.1.1970 00:00:00 GMT, so you have a hidden time zone conversion in your code. You can either

soulmerge
I set my default time zone, which wasn't set. Further investigation looks like I jumped the gun, the timestamp converts forwards and backwards just fine, and it makes it into the DB just fine. It seems to be a display issue only. Thanks for the help though.
Cory Dee
A: 

I just ran the following from the command line and got the following (expected) output. What happens if you run them?

$ php -r "echo date('H:i:s Y-m-d', mktime(24, 0, 0, 8, 29, 2009));"
00:00:00 2009-08-30

$ php -r "echo date('H:i:s Y-m-d', mktime(23, 0, 0, 8, 29, 2009));"
23:00:00 2009-08-29

$ php -r "echo date('H:i:s Y-m-d', mktime(22, 0, 0, 8, 29, 2009));"
22:00:00 2009-08-29
tj111