DateTimeZone::__constructtimezone_openCreates new DateTimeZone object DescriptionObject-oriented style
public DateTimeZone::__construct(string
$timezone )Procedural style DateTimeZonefalse timezone_open(string
$timezone )Creates a new DateTimeZone object.
A DateTimeZone object provides access to three different types of timezone
rules: UTC offset (type The DateTimeZone object can be attached to DateTime and DateTimeImmutable objects to be able to render the timezone encapsulated by these objects in a local timezone. Parameters
Return Values
Returns DateTimeZone on success.
Procedural style returns Errors/ExceptionsThis method throws DateInvalidTimeZoneException if the timezone supplied is not recognised as a valid timezone. Prior to PHP 8.3, this was an Exception instead. Changelog
Examples
Example #1 Creating and attaching DateTimeZone to a DateTimeImmutable
The above example will output: Thu, 02 Jun 2022 16:44:48 +0100 — Europe/London Thu, 02 Jun 2022 20:29:48 +0445 — +04:45 Thu, 02 Jun 2022 09:44:48 -0600 — -06:00 Thu, 02 Jun 2022 17:44:48 +0200 — CEST
Example #2 Catching errors when instantiating DateTimeZone
The above example will output: DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone (Mars/Phobos) DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone (Jupiter/Europa) |