English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP Date & Time Function Manual
The timezone_name_get() function returns the timezone name.
The timezone_name_get() function is an alias for DateTimeZone::getName(). It accepts a DateTimeZone object as a parameter and returns its timezone.
timezone_name_get($object)
Serial number | Parameters and descriptions |
---|---|
1 | object (required) This is a DateTimeZone object. |
The PHP timezone_name_get() function returns a string value that specifies the timezone of the given object.
This function was originally introduced in PHP version5.2introduced in version 5.2.0 and can be used in all higher versions.
The following examples demonstratetimezone_name_get()Usage of the function to return the timezone name-
<?php //Set timezone $tz = new DateTimeZone('Asia/Chongqing'); $res = timezone_name_get($tz); print("Timezone: ". $res); ?>Test and see‹/›
Output result
Timezone: Asia/Chongqing
Use two methods to return the timezone name:
<?php $dateSrc = '2007-04-19 12:50 GMT'; $dateTime = date_create($dateSrc); $DateTimeZone = timezone_open('Asia/Shanghai'); date_timezone_set($dateTime, $DateTimeZone); $NewDateTimeZone = date_timezone_get($dateTime); echo 'The new timezone is '. timezone_name_get($NewDateTimeZone); echo "\n"; #Use the second method $dateTime = new DateTime($dateSrc); $DateTimeZone = timezone_open('Asia/Shanghai'); $dateTime->setTimezone($DateTimeZone); echo 'The new timezone is '. $DateTimeZone;->getName(); ?>Test and see‹/›
Output result:
The new timezone is Asia/Shanghai The new timezone is Asia/Shanghai