Time zone issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Time zone issue

Post 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.
:?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What does getenv('TZ') tell you?
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

getenv('TZ'); returns nothing and echo getenv('TZ'); does the same thing.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post 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.
:)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
Post Reply