<?php
/* - - - - - - - - - - - - - - - - -
Object oriented style
- - - - - - - - - - - - - - - - - */
DateTime public DateTime::setTimezone ( DateTimeZone $timezone )
where,
$timezone = DateTimeZone object representing the desired time zone
?>
<?php
/* - - - - - - - - - - - - - - - - -
Procedural style
- - - - - - - - - - - - - - - - - */
DateTime date_timezone_set ( DateTime $object , DateTimeZone $timezone )
where,
$object = DateTime object
$timezone = DateTimeZone object representing the desired time zone
?>
<?php
$dtt01a = "Asia/Tokyo";
$date01 = new DateTime('now', new DateTimeZone($dtt01a));
echo $dtt01a . ':<br>' . $date01->format('Y-m-d H:i:sP') . "<br><br>";
$dtt01b = "Africa/Nairobi";
$date01->setTimezone(new DateTimeZone($dtt01b));
echo $dtt01b . ':<br>' . $date01->format('Y-m-d H:i:sP');
?>
<?php
$nytz02 = new DateTimeZone("America/New_York");
$dtm02 = new DateTime("now", $nytz02);
echo '<br>TIME ZONE INITIALLY SET:<br>';
$dftz21 = $dtm02->getTimezone();
echo $dftz21->getName();
echo '<br><br>REDEFINED TIME ZONE:<br>';
$sptz22 = new DateTimeZone("America/Sao_Paulo");
date_timezone_set($dtm02, $sptz22);
$nwtz22 = $dtm02->getTimezone();
echo $nwtz22->getName();
?>
<?php
$nytz31 = new DateTimeZone("Asia/Tokyo");
$dtm31 = new DateTime("now", $nytz31);
echo '<br>TIME ZONE INITIALLY SET:<br>';
$dftz31 = $dtm31->getTimezone();
echo $dftz31->getName();
echo '<br>', date_format($dtm31, "l F d Y H:i:s");
echo '<br><br>REDEFINED TIME ZONE:<br>';
$sptz32 = new DateTimeZone("America/New_York");
date_timezone_set($dtm31, $sptz32);
$nwtz31 = $dtm31->getTimezone();
echo $nwtz31->getName();
echo '<br>', date_format($dtm31, "l F d Y H:i:s");
?>