TimeZone
A time-zone, such as America/Mexico_City
.
There are three different types of time-zone rules:
- Fixed offset from UTC/Greenwich (
-06:00
). - Time-zone identifiers as published in the IANA time-zone database (
Australia/Hobart
). - Time-zone abbreviations (
BST
).
Instances of this class are immutable and not affected by any method calls.
Static Methods
utc
public static function utc(): static;
The time-zone for UTC/Greenwich.
system
public static function system(): static;
The system default time-zone.
identifiers
public static function identifiers(
TimeZoneGroup $group = TimeZoneGroup::All,
): array;
Gets the list of available time-zone identifiers.
The list of identifiers may grow over time. Results can be filtered by TimeZoneGroup
.
Return Values:
list<string>
the list of time-zone identifiers
countryIdentifiers
public static function countryIdentifiers(
string $code,
): array;
Gets the list of time-zone identifiers for a single country.
Parameters:
$code
a two-letter (uppercase) ISO 3166-1 country code
Return Values:
list<string>
the list of time-zone identifiers
Exceptions:
CountryException
if the country cannot be found
of
public static function of(
string $name,
): static;
Makes a new TimeZone
with the specified name.
Exceptions:
TimeZoneException
if the time-zone name cannot be found
fromNative
public static function fromNative(
NativeTimeZone $value,
): static;
Makes a new TimeZone
from a native DateTimeZone
.
fromOffset
public static function fromOffset(
Offset $offset,
): static;
Makes a new TimeZone
from a fixed Offset
.
Methods
__toString
public function __toString(): string;
Outputs this time-zone as a string
, using its name.
toNative
public function toNative(): NativeTimeZone;
Returns a native DateTimeZone
with the information of this time-zone.
toOffset
public function toOffset(
LocalDate|LocalDateTime|null $date = null,
): Offset;
Returns the offset of this time-zone from UTC/Greenwich on the specified date.
name
public function name(): string;
Returns the name of this time-zone.
type
public function type(): TimeZoneType;
Returns the type of this time-zone.
compareTo
public function compareTo(TimeZone $that): int;
Compares the name of this time-zone to the name of another time-zone.
Returns a negative integer, zero, or a positive integer depending on whether the name of this time-zone is less than, equal to, or greater than the name of the given time-zone name.
is
public function is(TimeZone $that): bool;
Checks if the given time-zone belongs to the same class and has the same name as this time-zone.
isNot
public function isNot(TimeZone $that): bool;
Checks if the given time-zone belongs to another class or has a different name than this time-zone.
isEqual
public function isEqual(TimeZone $that): bool;
Checks if the given time-zone has the same name as this time-zone.
isNotEqual
public function isNotEqual(TimeZone $that): bool;
Checks if the given time-zone has a different name from this time-zone.