date_timezone_set()
date_timezone_set() — Alias of DateTime::setTimezone().
Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.2.0, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
date_timezone_set() is an alias of DateTime::setTimezone(): same parameters, same return value.
Signature
date_timezone_set(DateTime $object, DateTimeZone $timezone): DateTime
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $object | DateTime | Procedural style only: A DateTime object returned by date_create(). The function modifies this object. |
| $timezone | DateTimeZone | A DateTimeZone object representing the desired time zone. |
Return value
Returns the DateTime object for method chaining. The underlying point-in-time is not changed when calling this method.
Example
A runnable snippet:
$date = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru')); echo $date->format('Y-m-d H:i:sP') . "\n"; $date->setTimezone(new DateTimeZone('Pacific/Chatham')); echo $date->format('Y-m-d H:i:sP') . "\n";
Output:
2000-01-01 00:00:00+12:00 2000-01-01 01:45:00+13:45
All PHP 8.5 built-in functions
Reference card built from the PHP manual page date_timezone_set() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.