PHP - Function date_timezone_get()



DateTimeZone date_timezone_get ( DateTime $object ) 

DateTimeZone DateTime::getTimezone ( void )

Definition and Usage

These functions return time zone relative to given DateTime.

The above two functions are equivalent and any of the functions can be used as shown below in the example.


Parameter Description
object Required. DateTime object

Return Value

Returns DateTimeZone object on success or FALSE on failure.


Following is the usage of this function. Use timezone_name_get() function to convert time zone object into string.

   $dateSrc = '2007-04-19 12:50 GMT';
   $dateTime = date_create( $dateSrc);;
   $DateTimeZone = date_timezone_get ( $dateTime );
   echo 'Return timeZone is '. timezone_name_get ($DateTimeZone);
   echo "\n";

   # Using second function.
   $dateTime = new DateTime($dateSrc);
   $DateTimeZone = $dateTime->getTimezone ();
   echo 'Return timeZone is '. timezone_name_get ($DateTimeZone);

This will produce the following result −

Return timeZone is America/Denver
Return timeZone is America/Denver