Change timezone

software development

#1

i need to change the timezone of the time(); function. currently it is set to pacific, but i need it to be UTC. Any ideas?

Thanks!

Web Design


#2

btw, this is for php :stuck_out_tongue:

Web Design


#3

putenv() should do the trick. You can scan down the page and see some timezone examples (look for “TZ=”)


:stuck_out_tongue: Maximum savings promo code: MaxSavingsAtDH


#4

time gives you the unix timestamp, where timezone is irrelevant. you can use [url=http://us2.php.net/gmdate]gmdate/url to format a timestamp in UTC.

track7 - my dream-hosted site


#5

This is correct.
However, you can also make Apache/PHP aware of your timezone (and consequently “tweak” the apparent server time) by editing your .htaccess file to contain the following line:

SetEnv TZ UTCThis will make subsequent calls to PHP functions like “date();” have awareness of the time zone you’re functioning with. The PHP function “time()” returns an unadjusted server time in seconds - the only way to play with that is to calculate the number of seconds of difference in your timezone and subtract it each and every usage (…I personally would not recommend it).

All world timezones can be tweaked with that “SetEnv TZ” line - to find the one for your area simply go to your Happy DreamHost Shell Prompt and enter the command “tzselect”, follow the instructions, and it’ll give ya the proper timezone to select - for example, if you’re in Philadelphia, PA, US like me the line would read:

SetEnv TZ America/New_YorkAnd as always, use caution when editing your .htaccess file.

ps. I’m not quite sure how (or even if) this variable may affect certain time-related mySQL functions.

pps. It does, however, seem to change and track Daylight Savings Time (…the 2nd dumbest invention of mankind) accurately.