How to set default timezone using PHP?

February 25, 2021

PHP has date_default_timezone_set() function that we can use to set the default timezone.

Here’s how to use this function:


echo date_default_timezone_get();




echo date_default_timezone_get();


Be careful, when you set the timezone, it will set in all date functions used inside the page. No matter what country it is, it will be that set timezone in all date functions.

Here is the list of all supported timezones.

It will return FALSE is you don’t pass the valid timezone.


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to uninstall Cocoapods from the Mac OS? #4 How to Use SQL MAX() Function with Dates? #5 How to add Read More Read Less Button using JavaScript? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

Apr 7 Solution for “Yarn build: Failed because of a stylelint error” Apr 7 Make sure your links have descriptive text Apr 7 How to add Laravel to WordPress using Sage theme (and install Tailwind CSS)? Apr 2 How to create a sidebar using pure CSS? Apr 1 How to switch dark and light themes using pure CSS? Apr 1 How to calculate elapsed time in JavaScript?

You might also like these

How can one check to see if a remote file exists using PHP?PHPMySQL queries to get data rows from previous month as well as from last 30 daysSQL/MySQLHow to get the full URL of current page in PHP?PHPHow to convert datetime to date format in JavaScript?JavaScriptHow to show slider value in HTML5 range input using JavaScript?HTMLWhat is Hoisting in JavaScript?JavaScriptThe SELECT DISTINCT Statement in SQLSQL/MySQLThe substr() method in JavaScript and how it’s different from substring()JavaScriptHow to detect the Blog Page in WordPress?WordPressHow to check if the page is single post page in WordPress?WordPressThe :last-of-type selectorCSSLearn how to give a temporary name to a column or to a table using SQL AliasesSQL/MySQL