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

PHP date_default_timezone_set() Function

PHP date_default_timezone_set() Function

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

Syntax:

date_default_timezone_set($timezone)

Parameter Values

Parameter Description
timezone This is a required parameter. This parameter defines the timezone to use like "UTC" or "Europe/Paris".

Here is an exmaple of date_default_timezone_set() function in PHP:

<html>
<body>
<?php
date_default_timezone_set("Asia/kolkata");
echo date_default_timezone_get();
?>
</body>
</html>
Output:
Asia/kolkata

Example 2

<html>
<body>
<?php
date_default_timezone_set("America/chicago");  
echo date_default_timezone_get();  
?>
</body>
</html>
Output:
America/chicago

Example 3

<html>
<body>
<?php
date_default_timezone_set("America/New_York");    
echo date_default_timezone_get();  
?>
</body>
</html>
Output:
America/New_York

No Sidebar ads