Copyright © tutorialspoint.com

PHP Function date_timezone_get()

previous
Advertisements

Syntax

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.

Paramters

ParameterDescription
objectRequired. DateTime object

Return Value

Returns DateTimeZone object on success or FALSE on failure.

Example

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

<?php
   $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 following result:

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

Copyright © tutorialspoint.com