PHP - Function timezone_name_get()



string timezone_name_get ( DateTimeZone $object );

string DateTimeZone::getName ( void );

Definition and Usage

These functions return returns the name of the timezone.

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


Parameter Description
DateTimeZone A date and time zone object

Return Value

Returns array on success or FALSE on failure.


Following is the usage of this function −

   $dateSrc = '2007-04-19 12:50 GMT';
   $dateTime = date_create( $dateSrc);
   $DateTimeZone = timezone_open ( 'America/Chicago' );
   date_timezone_set( $dateTime, $DateTimeZone );
   $NewDateTimeZone = date_timezone_get($dateTime);
   echo 'New timeZone is '. timezone_name_get($NewDateTimeZone);
   echo "\n";

   # Using second function.
   $dateTime = new DateTime($dateSrc);
   $DateTimeZone = timezone_open ( 'America/Chicago' );
   $dateTime->setTimezone( $DateTimeZone );
   echo 'New timeZone is '. $DateTimeZone->getName ();

This will produce the following result −

New timeZone is America/Chicago
New timeZone is America/Chicago