The Wayback Machine - https://web.archive.org/web/20240213201405/https://www.geeksforgeeks.org/php-date_default_timezone_get-function/
Open In App
Related Articles

PHP | date_default_timezone_get() Function

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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:  

  • Reading the timezone using the date_default_timezone_set() function.
  • Before PHP 5.4.0, Reading the TZ environment variable.
  • Reading the value of the date.timezone ini option
  • Before PHP 5.4.0, Querying the host operating system (if supported and allowed by the OS). This uses an algorithm that has to guess the timezone.

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




<?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




<?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
 

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Looking for a place to share your ideas, learn, and connect? Our Community portal is just the spot! Come join us and see what all the buzz is about!


Last Updated : 09 Nov, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials