Created
September 9, 2011 16:52
-
-
Save sobstel/1206722 to your computer and use it in GitHub Desktop.
PHP: Converting DateTime between timezones
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 | |
// now | |
$date = date_create('2010-12-31 22:00:01', timezone_open('Europe/Amsterdam')); | |
// Buenos Aires | |
date_timezone_set($date, timezone_open('America/Argentina/Buenos_Aires')); | |
echo $date->format('Y-m-d H:i:s'); | |
// 2010-12-31 18:00:01 | |
// UTC | |
date_timezone_set($date, timezone_open('UTC')); | |
echo $date->format('Y-m-d H:i:s'); | |
// 2010-12-31 20:00:01 | |
// London | |
date_timezone_set($date, timezone_open('Europe/London')); | |
echo $date->format('Y-m-d H:i:s'); | |
// 2010-12-31 21:00:01 | |
// Maldives | |
date_timezone_set($date, timezone_open('Indian/Maldives')); | |
echo $date->format('Y-m-d H:i:s'); | |
// 2011-01-01 02:00:01 | |
// Melbourne | |
date_timezone_set($date, timezone_open('Australia/Melbourne')); | |
echo $date->format('Y-m-d H:i:s'); | |
// 2011-01-01 08:00:01 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what should we do for the "+05:30" format?