<?php
/* - - - - - - - - - - - - - - - - - - -
Object oriented style I
- - - - - - - - - - - - - - - - - - - */
DateTimeZone|false public DateTime::getTimezone ( )
?>
<?php
/* - - - - - - - - - - - - - - - - - - - -
Object oriented style II
- - - - - - - - - - - - - - - - - - - - */
DateTimeZone|false public DateTimeImmutable::getTimezone ( )
?>
<?php
/* - - - - - - - - - - - - - - - - - - - - -
Object oriented style III
- - - - - - - - - - - - - - - - - - - - - */
DateTimeZone|false public DateTimeInterface::getTimezone ( )
?>
<?php
/* - - - - - - - - - - - - - - - - -
Procedural style
- - - - - - - - - - - - - - - - - */
DateTimeZone|false date_timezone_get ( DateTimeInterface $object )
where,
$object = DateTimeZone object representing the desired time zone
?>
<?php
$dtz011 = new DateTimeZone('Africa/Sao_Tome');
$dtm011 = new DateTime("now", $dtz011);
echo 'TIME ZONE HAS BEEN ESTABLISHED AS:<br>';
$tz011 = $dtm011->getTimezone();
echo $tz011->getName();
?>
<?php
$dtt022 = date_create("now");
echo 'TIME ZONE HAS BEEN ESTABLISHED AS:<br>';
$dtz022 = date_timezone_get($dtt022);
echo timezone_name_get($dtz022);
?>
<?php
$date = new DateTime("now", new DateTimeZone('Europe/London'));
$tz = $date->getTimezone();
echo $tz->getName();
?>
<?php
$date = new DateTimeImmutable("now", new DateTimeZone('Europe/London'));
$tz = $date->getTimezone();
echo $tz->getName();
?>
<?php
// Set the default time zone
date_default_timezone_set("Europe/Lisbon");
$datetime = date_create("now");
$tz = date_timezone_get($datetime);
echo "Default timezone:<br>" . timezone_name_get($tz) . "<br><br>";
$datetime = date_create("now");
// Set the new time zone
$la_time = timezone_open("America/New_York");
date_timezone_set($datetime, $la_time);
$tz = date_timezone_get($datetime);
echo "New timezone:<br>" . timezone_name_get($tz);
?>