Open In App

PHP | date_default_timezone_get() Function

The date_default_timezone_get() function is an inbuilt function in PHP which is used to gets the default timezone used by all date/time functions in a script.

Syntax:  



string date_default_timezone_get( void )

Parameter: This function does not accept any parameter.
Return Value: This function returns a string.

Note: This function returns the default timezone by:  



If any statement of the above is not true then date_default_timezone_get() will return a default timezone of UTC. 
Below programs illustrate the date_default_timezone_get() function in PHP:

Program 1:  




<?php
 
// Set the default timezone
date_default_timezone_set('Asia/Kolkata');
 
// Create timezone object
$timezone_object = date_default_timezone_get();
 
// If timezone object is true
if ($timezone_object) {
    echo 'date_default_timezone_set: ' . date_default_timezone_get();
}
?>

Output: 
date_default_timezone_set: Asia/Kolkata

 

Program 2:  




<?php
 
// Set the default timezone
date_default_timezone_set('Asia/Kolkata');
 
echo date_default_timezone_get() . ' => ' . date('e') . ' => ' . date('T');
?>

Output: 
Asia/Kolkata => Asia/Kolkata => IST

 

Related Articles: 

Reference: http://php.net/manual/en/function.date-default-timezone-get.php
 

Article Tags :