ID #258

How do I change timezone for PHP?

Applies to: Grid System

There are at least 2 ways to cause PHP to behave as if it was in the timezone of your choice.

1. Follow this other FAQ to change timezone for your entire account.

2. If you only want particular PHP scripts (and not shell or other 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";
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:

If you are looking for information about changing timezones for MySQL, look here.

Last update: 2010-10-03 16:57
Author: FAQ Admin
Revision: 1.3

Digg it! Share on Facebook Print this record Send FAQ to a friend Show this as PDF file
Please rate this FAQ:

Average rating: 3.66 (35 Votes)

completely useless 1 2 3 4 5 most valuable

You can comment this FAQ

Comment of Anonymous:
Be sure to use the "underscore" (_) character in the syntax when needed, such as putenv("TZ=America/Los_Angeles")

Added at: 2005-04-28 13:45

Comment of Anonymous:
H:i:s, not h:i:s should be used for the time
Added at: 2009-08-25 14:09

Comment of David G:
Very nice, I have always used php.ini to specify a timezone.
I will keep this method in mind for any future issues.

Added at: 2011-08-30 20:42