date_default_timezone_set()

Set the default timezone for the current script

date_default_timezone_set() changes the default timezone used by date/time functions in the current request.

date_default_timezone_set('Asia/Kolkata');
echo date('Y-m-d H:i:s T');

Use a valid timezone identifier such as Asia/Kolkata rather than a fixed numeric offset when daylight-saving rules may matter.

Irrespective of time zone set in php.ini file , we can set the time zone of the server for our script by using date_default_timezone_set() function.
The list of applicable time zone identifier is available here.
Here is the sample code to set the time zone.
<?Php
echo date_default_timezone_set();
?>
We can set it like this
date_default_timezone_set('America/Chicago');
After setting the time zone , you can read the same by using date_default_timezone_get() function.

Setting the time zone in php.ini file

You can set the default time zone at php.ini file. If you are using for first time then search for the line saying
;date.timezone =
Change it to
date.timezone ="Asia/Calcutta";
You can change the area as per your requirement by using time zone identifier .

Example: Dynamically Switching Time Zones

date_default_timezone_set('America/New_York');
echo date('Y-m-d H:i:s').'<br>'; // Output: Current time in New York
date_default_timezone_set('Asia/Kolkata');
echo date('Y-m-d H:i:s'); // Output: Current time in Kolkata
Output
2026-09-29 22:48:46
2026-09-30 08:18:46

Example: Listing All Available Time Zones

$timezones = timezone_identifiers_list();
print_r($timezones);
Or to display as list
$timezones = timezone_identifiers_list();
foreach($timezones as $key=>$value){
	echo "$key : $value".'<br>';
}

Creating a dropdown list for user selection of Timezone

PHP Date Functions date_default_timezone_get() get the time zone


Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer