Page 1 of 1

Time zone issue

Posted: Fri Mar 02, 2007 8:31 pm
by Bill H
Okay, I am really clutching at straws here, but.

Code: Select all

echo "Printed ",date("M d, Y")," at ",date("h:i a");
The above line prints a date that is correct but a time that is off by two hours from our local time here in fun-packed, downtown, metropolitan San Diego CA. The host assures me that the server is set to PST and has told me in a rather snotty tone to correct my script to "produce the correct time." I cannot see, however, what part of the above code is adding two hours to the time obtained from the server, as is claimed by the host.

Perhaps someone can:
a) tell me what part of the code is adding two hours
or
b) confirm that my host is full of it.
:?

Posted: Fri Mar 02, 2007 8:42 pm
by feyd
What does getenv('TZ') tell you?

Posted: Fri Mar 02, 2007 11:37 pm
by Bill H
getenv('TZ'); returns nothing and echo getenv('TZ'); does the same thing.

Posted: Fri Mar 02, 2007 11:42 pm
by feyd
Then it would appear the server is not set correctly as without the "TZ" environment variable set, PHP has no other choices but the current time setting of the server.

You can even ask PHP to output the current time offset from GMT; date('O T') for example.

Posted: Fri Mar 02, 2007 11:47 pm
by Bill H
Yeah, which is the problem, as they were saying it was set to PST but the script (in OP) was showing CST. They kept saying my script was wrong but, guess what - as of this point the script is now returning PST. I'm sure they would try to say their server was set to that zone all along, but to heck with it. It's okay now, and that's all I care about.

I'm way too old to be trying to "score points" with anybody.
:)

Posted: Fri Mar 02, 2007 11:58 pm
by feyd
Well.. you can always ask the server to give you the time in GMT, perform a bit of math and you get time in PST.

Alternately, you may also get good performance from Stryk's function: viewtopic.php?t=64340