Friday, June 10, 2011

PHP Conversion of Time and Date (Timezone)

An example to convert date and time from one timezone to another:

The Code:

$current_date = date('Y-m-d');
$time_to_convert = '03:05:06';


$date = new DateTime($current_date.$time_to_convert, new DateTimeZone('Asia/Taipei'));
echo '
'.$date->format('Y-m-d H:i:s') . '
';

$date->setTimezone(new DateTimeZone('America/New_York'));
echo '
'.$date->format('Y-m-d H:i:s') . '
';
?>


The Output:

2011-06-10 03:05:06
2011-06-09 15:05:06