date_timezone_get


php apg

RETURNS the time zone relative for the DateTime object.



<?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

?>

 $object 


The DateTimeInterface object.





For Procedural style, only:
A DateTime object returned by the function date_create.

Returns the DateTimeZone object on success or FALSE on failure.



  1 EXERCISE   

<?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();

?> 

  2 EXERCISE   

<?php

$dtt022 
= date_create("now");

echo 
'TIME ZONE HAS BEEN ESTABLISHED AS:<br>'; 

$dtz022 = date_timezone_get($dtt022);

echo 
timezone_name_get($dtz022);

?> 

  3 EXERCISE   

<?php

$date 
= new DateTime("now", new DateTimeZone('Europe/London'));

$tz = $date->getTimezone();

echo 
$tz->getName();

?>

  4 EXERCISE   

<?php

$date 
= new DateTimeImmutable("now", new DateTimeZone('Europe/London'));

$tz = $date->getTimezone();

echo 
$tz->getName();

?>

  5 EXERCISE   

<?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);

?>