Created
July 3, 2014 09:21
-
-
Save peterlozano/a4e9b7947953958a6964 to your computer and use it in GitHub Desktop.
PHP: Convert dates between timezones, independent of php timezone configuration.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$from_value = '2011-10-04 00:00:00'; | |
// Create a date using the original timezone. | |
$from_timezone = 'America/New_York'; | |
$date = new DateTime($from_value, new DateTimeZone($from_timezone)); | |
// Move the date to another timezone. | |
$to_timezone = 'UTC'; | |
$date->setTimezone(new DateTimeZone($to_timezone)); | |
// Get the destination value in the desired format. | |
$to_format = 'Y-m-d\TH:i:s'; //$to_format = 'Y-m-d H:i:s'; | |
$to_value = $date->format($to_format); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment