How to convert time from one timezone to another in PHP



PHP Snippet 1:

date_default_timezone_set('Europe/London');

$datetime = new DateTime('2008-08-03 12:35:23');
echo $datetime->format('Y-m-d H:i:s') . "\n";
$la_time = new DateTimeZone('America/Los_Angeles');
$datetime->setTimezone($la_time);
echo $datetime->format('Y-m-d H:i:s');

PHP Snippet 2:

$tz1 = 'Europe/Vilnius';
$tz2 = 'Africa/Dakar';
$a='16';
$b='17';
$match_time = date("H:i", strtotime($a.":".$b));
$dt1 = new DateTime($match_time, new DateTimeZone($tz1));
$dt2 = new DateTime($match_time, new DateTimeZone($tz2));

echo "match date".$match_time;
echo "dt1".$dt1->format('Y-m-d H:i:s');
echo "dt2".$dt2->format('Y-m-d H:i:s');

PHP Snippet 3:

<?php
$dt = new DateTime("16:17", new DateTimeZone('Europe/Warsaw'));