The date_default_timezone_set() function is an inbuilt function in PHP which is used to set the default timezone used by all date/time functions in a script. This function returns False if the timezone is not valid, or True otherwise.
Syntax:
bool date_default_timezone_set( $timezone_identifier )
Parameters: This function accepts single parameter $timezone_identifier which is mandatory. This parameter set the timezone identifier, like UTC or Asia/Kolkata.
Return Value: This function returns False if the timezone_identifier is not valid, or True otherwise.
Below programs illustrate the date_default_timezone_set() function in PHP:
Program 1:
<?php // Set timezone date_default_timezone_set('Asia/Kolkata'); // Create $timezone_object = date_default_timezone_get(); // Compare the timezone with ini-set timezone if (strcmp($timezone_object, ini_get('date.timezone'))){ echo 'Script timezone differs from ini-set timezone.'; } else { echo 'Script timezone and ini-set timezone match.'; } ?> |
Script timezone differs from ini-set timezone.
Program 2:
<?php // Set the timezone date_default_timezone_set('Asia/Dubai'); // Create the timezone object $timezone_object = date_default_timezone_get(); // Compare the timezone with ini-set timezone if (strcmp($timezone_object, ini_get('date.timezone'))){ echo 'Script timezone differs from ini-set timezone.'; } else { echo 'Script timezone and ini-set timezone match.'; } ?> |
Script timezone differs from ini-set timezone.
Related Articles:
Reference: http://php.net/manual/en/function.date-default-timezone-set.php
Recommended Posts:
- How to Check a Function is a Generator Function or not using JavaScript ?
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- PHP | key() Function
- p5.js | nfp() Function
- PHP | Ds\Map get() Function
- p5.js | nfs() Function
- D3.js now() function
- p5.js | nfc() function
- PHP | pos() Function
- CSS | url() Function
- PHP | end() Function
- CSS env() Function
- PHP | Ds\Map xor() Function
- PHP | Ds\Map put() Function
- PHP | ord() Function
- PHP | each() Function
- PHP | Ds\Set xor() Function
- D3.js | d3.map.set() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

