In this article, you will learn how to set the timezone for a date. The date_timezone_set() function set the time zone for the given DateTime object.
What is the syntax of the date_timezone_set() function in PHP?
date_timezone_set(object, timezone)
Parameter | Description |
---|---|
object | Required. Specifies a DateTime object returned by date_create(). This function modifies this object |
timezone | Required. Specifies a DateTimeZone object that represents the desired time zone. |
Example of the date_timezone_set() function
Example 1. In this example, we create a DateTime object using date_create() method and then set the timezone for it.
<?php
$d=date_create("2014-06-15",timezone_open("Europe/Paris"));
echo date_format($d,"Y-m-d H:i:sP");
?>