Knowledgebase: Programming & Languages > PHP
How to change timezone in PHP scripts?
Posted by Andy Williams on 19 June 2009 06:17 PM

If you only want particular PHP scripts (not a cgi scripts) to use a specific timezone, set the timezone environmental variable in your PHP code like so:

<?
echo "Original Time: ". date("h:i:s")."\n";
putenv("TZ=US/Eastern");
echo "New Time: ". date("h:i:s")."\n";
?>

If you put the line putenv("TZ=US/Eastern"); in a file that is
include()'ed by all your other PHP scripts, then all your PHP scripts will use that timezone.

A list of timezones to choose from, other than "US/Eastern" for your putenv() is here:

http://www.theprojects.org/dev/zone.txt

(346 vote(s))
Helpful
Not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).