<?php
// Define the timezones and their offsets
// 'Zone Label' => Offset
$timezones = Array('GMT' => 0, 'US EST' => -5, 'US PST' => -8);
// Set up a form to change the timezone
// Automatically update the page on a timezone change
echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<select name="tz" onChange="this.form.submit();">';
// Create a drop-down list of timezones
foreach($timezones as $zone => $offset)
{
echo '<option value="'.$offset.'_'.$zone.'"';
if($offset.'_'.$zone == $_POST['tz']){ echo ' selected'; }
echo '>'.$zone.'</option>';
}
echo '</select>
</form>';
// Give a default zone of there is no zone given
if(!isset($_POST['tz']))
{
$_POST['tz'] == '-5_US EST';
}
// Get the offset and timezone from the POST array
list($offset, $zone) = explode('_', $_POST['tz']);
// Display the current zone and its offset
echo 'The timezone is: '.$zone.' ( '.$offset.' )<br>';
// Display the current time
echo 'The current time is: '.gmdate('m/d/Y h:i a', time()+3600*($offset+date("I")));
?>
That will output:
The timezone is: US EST ( -5 )
The current time is: 10/13/2005 01:18 am
[man]gmdate/man <-- Read the user notes
Basically, what the last line does is create a date (just like date('m/d/Y') would) based upon a specific time. The time is defined as:
now + ( (60 seconds 60 minutes) (timezone_offset + DST) )
So you take the timezone hour offset, add the DST offset (1 if it's the winter, 0 if it's the summer), and mulitply that by the amount of seconds in one hour (3600) and then add that to the "now" timestamp. Then the gmdate() function displays the result.
Just add the time-zones to the array, and voila!!
~Brett