PHP Function Reference

PHP DateTimeZone - getName() Method



The PHP DateTimeZone::getName() method returns the name of the timezone. The timezone_name_get() function is an alias of this method.

Syntax

//Object-oriented style
public DateTimeZone::getName()

//Procedural style
timezone_name_get(object)

Parameters

object Required. For procedural style only: A DateTimeZone object for which to get a name.

Return Value

Returns one of the timezone names in the list of timezones.

Example: using both styles

The example below shows the usage of DateTimeZone::getName() method.

<?php
//creating a DateTimeZone object 
$tz1 = new DateTimeZone("Europe/London");

//displaying the name of the timezone
//using Object-oriented style
echo "The timezone is: ".$tz1->getName()."\n";

//creating a DateTimeZone object
$tz2 = new DateTimeZone("America/Chicago");

//displaying the name of the timezone
//using Procedural style
echo "The timezone is: ".timezone_name_get($tz2)."\n";
?>

The output of the above code will be:

The timezone is: Europe/London
The timezone is: America/Chicago

❮ PHP Date and Time Reference