Skip to content

Instantly share code, notes, and snippets.

@sobstel
Created September 9, 2011 16:52
Show Gist options
  • Save sobstel/1206722 to your computer and use it in GitHub Desktop.
Save sobstel/1206722 to your computer and use it in GitHub Desktop.
PHP: Converting DateTime between timezones
<?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
@mclarenmervin
Copy link

what should we do for the "+05:30" format?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment