PHP timezone_name_get() Function
Definition and Usage
The timezone_name_get() function is an alias of DateTimeZone::getName(). It accepts a DateTimeZone object as a parameter and returns its timezone.
Syntax
timezone_name_get($object)
Parameters
| Sr.No | Parameter & Description |
|---|---|
| 1 |
object (Mandatory) This is a DateTimeZone object. |
Return Values
PHP timezone_name_get() function returns a string value specifying the timezone of the given object.
PHP Version
This function was first introduced in PHP Version 5.2.0 and, works with all the later versions.
Example
Following example demonstrates the usage of the timezone_name_get() function −
Live Demo
<?php
//setting the timezone
$tz = new DateTimeZone('Indian/Mahe');
$res = timezone_name_get($tz);
print("Timezone: ".$res);
?>
This will produce following result −
Timezone: Indian/Mahe
Example
$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
php_function_reference.htm
Advertisements