English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP timezone_name_get() Function Usage and Example

PHP Date & Time Function Manual

The timezone_name_get() function returns the timezone name.

Definition and usage

The timezone_name_get() function is an alias for DateTimeZone::getName(). It accepts a DateTimeZone object as a parameter and returns its timezone.

Syntax

timezone_name_get($object)

Parameter

Serial numberParameters and descriptions
1

object (required)

This is a DateTimeZone object.

Return value

The PHP timezone_name_get() function returns a string value that specifies the timezone of the given object.

PHP version

This function was originally introduced in PHP version5.2introduced in version 5.2.0 and can be used in all higher versions.

Online example

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

Online example

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