Open In App

PHP | DateTimeZone::getName() Function

The DateTimeZone::getName() function is an inbuilt function in PHP which is used to return the name of the created timezone.

Syntax:



DateTimeZone::getName()

Parameters: This function does not accept any parameter.

Return Values:: This function return the name of the created timezone.



Below programs illustrate the DateTimeZone::getName() function:

Program 1:




<?php
// PHP program to illustrate DateTimeZone::getName()
// function
  
// Initialising a timezone
$timeZone = "Asia/Kolkata";
    
// Creating DateTimeZone() object with
// the above timezone
$DatetimeZone = new DateTimeZone($timeZone); 
    
// Getting the name of timezone  
print_r($DatetimeZone->getName()); 
?>

Output:

Asia/Kolkata

Program 2:




<?php
// PHP program to illustrate DateTimeZone::getName()
// function
    
// Creating DateTimeZone() object with
// a specific timezone
$DatetimeZone = new DateTimeZone("Asia/Singapore"); 
    
// Getting the name of timezone  
print_r($DatetimeZone->getName()); 
?>

Output:

Asia/Singapore

Reference
https://devdocs.io/php/datetimezone.getname

Article Tags :