HomePHP & MySQLDate functions in PHPPHP date_default_timezone_set(): Set default time zone UTC Aner Barrena October 12, 2020 Date functions in PHP, PHP & MySQL New post to review the function of PHP date_default_timezone_set() that sets the default time zone. This PHP function sets the default time zone in all of the date functions we use in our PHP script. Let’s see what the date_default_timezone_set() nomenclature looks like. Related function: date_default_timezone_get() Syntax of date_default_timezone_set() PHP boolean date_default_timezone_set ( string ) 1 boolean date_default_timezone_set ( string ) In the code we can see that the function only needs to be passed a string with the time zone, in my case for example it would pass ‘Europe/Berlin‘. Here we can see a list of the supported time zones. Example of date_default_timezone_set() We will see in the following lines a simple example where we will establish by default ‘Australia/Melbourne’ and we will ask the system the default time zone (it would have to return the same): PHP <?php //We set the default timezone date_default_timezone_set('Australia/Melbourne'); //We get the default timezone $timezone = date_default_timezone_get(); echo 'Default tomezone: ' . $timezone; ?> 1234567 <?php //We set the default timezone date_default_timezone_set('Australia/Melbourne'); //We get the default timezone $timezone = date_default_timezone_get(); echo 'Default tomezone: ' . $timezone;?> PHP functions with dates Dates in PHP Related posts: PHP date_default_timezone_get(): Get default time zone UTC How to detect links in a text string with PHP PHP header(): operation and redirect 301 with the Location header