Home >>PHP Date Time Functions >PHP date_timezone_set() Function
PHP date_timezone_set() function is used to sets the time zone for the given DateTime object. It returns the DateTime object on success or False on failure. It accepts two parameters $object and the $timezoe.
Syntax:
date_timezone_set(object, timezone);
Parameter | Description |
---|---|
object | This is a required parameter. This parameter defines the DateTime object returned by date_create(). |
timezone | This is a required parameter. The parameter defines the DateTimeZone object that represents the desired time zone. |
Here is an example of date_timezone_set() function in PHP:
<html> <body> <?php $date=date_create(); echo date_format($date,"d-M-Y H:i:s P")."<br>"; // current UTC date_timezone_set($date,timezone_open("Asia/kolkata")); echo date_format($date,"d-M-Y H:i:s P"); // india time ?> </body> </html>
Example 2:
<html> <body> <?php $date=date_create("14-02-2020",timezone_open("Asia/kolkata")); echo date_format($date,"d-M-Y H:i:s P")."<br>"; // actual timezone date_timezone_set($date,timezone_open("Europe/Paris")); echo date_format($date,"d-M-Y H:i:s P"); // changed timezone ?> </body> </html>