Monday, 29 May 2017 08:06

Using PHP date_default_timezone_set() Function

Syntax

date_default_timezone_set(timezone);

The date_default_timezone_set() function set the default timezone.This means that your date and time will assume the set time zone. 

Check time zone list here

Example 1
<?php
date_default_timezone_set("Asia/Dubai");
echo date_default_timezone_get();
?>

 

Result
Asia/Dubai

 

Example 2

The example below will display date output with php default time zone and time zone set to Asia/Dubai which is +4 GMT.Note the time difference.

<?php
echo date("Y-m-d H:i:s");
echo "<br>"; date_default_timezone_set("Asia/Dubai"); echo date("Y-m-d H:i:s"); ?>

 

Result
2017-05-29 08:48:03
2017-05-29 12:48:03
Last modified on Monday, 29 May 2017 08:57
More in this category: « PHP date_format() Function

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.