PHP Tutorial - PHP date_timezone_set() Function






Definition

The date_timezone_set() function sets the time zone for the DateTime object.

Syntax

PHP date_timezone_set() Function has the following syntax.

date_timezone_set(object,timezone);

Parameter

PHP date_timezone_set() Function has the following syntax.

ParameterIs RequiredDescription
objectRequired.DateTime object returned by date_create().
timezoneRequired.DateTimeZone object that represents the desired time zone.

Return

PHP date_timezone_set() Function returns the DateTime object for method chaining. FALSE on failure.





Example

Set the timezone for the DateTime object:


<?php
    $date=date_create("2013-05-25",timezone_open("Indian/Kerguelen"));
    echo date_format($date,"Y-m-d H:i:sP");
?>

The code above generates the following result.