PHP | timezone_name_get() Function
Last Updated :
16 Aug, 2018
The timezone_name_get() function is an inbuilt function in PHP which is used to return the name of the timezone. The date time object is sent as a parameter to the timezone_name_get() function and it returns the name of the timezone on success or False on failure.
Syntax:
string timezone_name_get( $object )
Parameters: This function accepts single parameter $object which is mandatory. It is used to specifies the DateTimeZone object.
Return Value: This function returns the name of the timezone on success or False on failure.
Exceptions: The timezone_name_get() function is an alias of DateTimeZone::getName() function.
Below programs illustrate the timezone_name_get() function in PHP:
Program 1:
<?php
$timezone = timezone_open( "America/Chicago" );
echo ( "The name of the timezone is " . timezone_name_get( $timezone ));
?>
|
Output:
The name of the timezone is America/Chicago
Program 2:
<?php
echo ( "Default time zone is " . date_default_timezone_get());
echo "\n" ;
$new_timezone = 'America/Chicago' ;
if ( date_default_timezone_set( $new_timezone ) )
{
echo "New time zone is " . date_default_timezone_get();
}
?>
|
Output:
Default time zone is UTC
New time zone is America/Chicago
Related Articles:
Reference: http://php.net/manual/en/function.timezone-name-get.php
Share your thoughts in the comments
Please Login to comment...