drew010 is correct of course, but if your web host provider is in the same timezone as you, then ask them to change it.
If you're on a Unix based system, you can take advantage of the TZ environment variable. As, in:
$tz = getenv('TZ'); // Get current server time zone setting
echo "Current timezone setting: $tz <br>";
putenv("TZ=EST5EDT"); // Change to US Eastern time zone or whatever you want
$lt = localtime(time(), TRUE);
echo "EST local time: $lt['tm_hour']:$lt['tm_min']:$lt['tm_sec'] <br>";
putenv("TZ=$tz"); // Change it back to the original server time zone
The above code is an example where you don't have to worry about the offsets from UTC of different time zones, or whether DST is in effect. Just set the appropriate zone and let your system/server do the rest. It fools the system into thinking it's in a different time zone, long enough for you to get the time in the zone you want.
If you're not on Unix based system, then you could use an associative array that contains offsets from UTC. Here is an example to get a Pacific time:
$tz = array (
'AST' => -4 // Atlantic Standard
'CST' => -6, // Central Standard
'EST' => -5, // Eastern Standard
'PST' => -8, // Pacific Standard
'HST' => -10, // Hawaii Standard
// etc. etc. etc. - Just put as many as you need here
'NZT' => +12 // New Zealand Standard
);
$pacific_time = time() + ($tz['PST'] * 3600);
echo gmstrftime('%c', $pacific_time);
The 'TZ' environment variable should take care of DST automatically. But, here's another way to handle DST:
$tz = array (
'AST' => -4 // Atlantic Standard
'CST' => -6, // Central Standard
'EST' => -5, // Eastern Standard
'PST' => -8, // Pacific Standard
'HST' => -10, // Hawaii Standard
// etc. etc. etc. - Just put as many as you need here
'NZT' => +12 // New Zealand Standard
);
$pacific_time = time() + ($tz['PST'] * 3600);
$lt = localtime($pacific_time, TRUE);
if ($lt['tm_isdst'])
$pacific_time += 3600;
echo gmstrftime('%c', $pacific_time);
Various helpful links:-
getenv -- Gets the value of an environment variable:
http://us2.php.net/manual/en/function.getenv.php
putenv -- Sets the value of an environment variable:
http://us2.php.net/manual/en/function.putenv.php
US time zones:
http://tycho.usno.navy.mil/zones.html
World time zones:
http://tycho.usno.navy.mil/tzones.html
Time Zone and Daylight Saving Time Data:
http://www.twinsun.com/tz/tz-link.htm
localtime -- Get the local time:
http://us2.php.net/localtime
date -- Format a local time/date (which accepts Timezone offset in seconds):
http://us3.php.net/date
strftime -- Format a local time/date according to locale settings:
http://us3.php.net/strftime/
gmstrftime -- Format a GMT/UTC time/date according to locale settings:
http://us3.php.net/manual/en/function.gmstrftime.php
hth.
🙂