tags:

views:

36

answers:

2

how can i display diffrent timezones time in a page with php?

like

Eastern:    02:23 AM
Central:    02:23 AM
Asia/India: 02:23 AM
Mountain:   02:23 AM
Pacific:    02:23 AM
+7  A: 
foreach (DateTimeZone::listIdentifiers() as $timezone)
{
    $time = new DateTime('now', new DateTimeZone($timezone));
    echo $timezone . ': ' . $time->format('c').'<br>';
}
Sjoerd
Tiny improvement suggestion: since you are just outputting the time, there is no need to instantiate a new DateTime object for each timezone. Instantiate the object before the loop and then just `$dateTime->setTimezone(new DateTimeZone($timezone));`
Gordon
+1  A: 

You can do something like this:

$date = new DateTime("now", new DateTimeZone('Europe/London'));
$tz = $date->getTimezone();
echo $tz->getName() . " - " . $date->format('H:m');
xil3