DateTimeZone::__constructtimezone_openCreates new DateTimeZone object
&reftitle.description;
&style.oop;publicDateTimeZone::__constructstringtimezone&style.procedural;DateTimeZonefalsetimezone_openstringtimezone
Creates a new DateTimeZone object.
A DateTimeZone object provides access to three different types of timezone
rules: UTC offset (type 1), timezone abbreviation (type
2), and timezone
identifiers as published in the IANA timezone database
(type 3).
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.
&reftitle.parameters;
timezone
One of the supported timezone names,
an offset value (+0200), or a timezone abbreviation (BST).
&reftitle.returnvalues;
Returns DateTimeZone on success.
&return.falseforfailure.style.procedural;
&reftitle.errors;
This method throws
DateInvalidTimeZoneException if the timezone supplied is not
recognised as a valid timezone. Prior to PHP 8.3, this was an
Exception instead.
&reftitle.changelog;
&Version;&Description;8.3.0
Invalid values now return a
DateInvalidTimeZoneException instead of
a generic Exception.
&reftitle.examples;
Creating and attaching DateTimeZone to a DateTimeImmutable
setTimezone($tzo);
echo $local->format(DateTimeInterface::RFC2822 . ' — e') . "\n";
}
]]>
&example.outputs;
Catching errors when instantiating DateTimeZone
getName() . "\n";
} catch(Exception $e) {
echo $e->getMessage() . "\n";
}
}
]]>
&example.outputs;