Home >>PHP Date Time Functions >PHP date_default_timezone_get() Function

PHP date_default_timezone_get() Function

PHP date_default_timezone_get() Function

PHP date_default_timezone_get() function is used to get the default timezone used by all date/time functions in the program. It returns false if the timezone is invalid, othewise it returns true value.

Syntax:

date_default_timezone_get()

Here is an exmaple of date_default_timezone_set() in PHP:

<html>
<body>
<?php
echo date_default_timezone_get();
?>
</body>
</html>
Output:
UTC

Example 2

<html>
<body>
<?php
 echo "Print old time : ". date_default_timezone_get()."<br>";  
   $time = 'America/Chicago';  
if( date_default_timezone_set( $time) )
 {  
      echo "Print New time : ". date_default_timezone_get();  
  }  
?>
</body>
</html>
Output:
Print old time : Europe/Berlin
Print New time : America/Chicago

No Sidebar ads