TimeZoneInfo
extends DateTimeZone
in package
implements
JsonSerializable, Stringable, IComparable, IEquatable
Represents a time zone.
Table of Contents
Interfaces
- JsonSerializable
- Stringable
- IComparable
- Provides an interface for comparison between objects. Allows for order/sorting instances.
- IEquatable
- Provides an interface for determining the value-equality of two objects.
Methods
- __construct() : TimeZoneInfo
- Constructs a new TimeZoneInfo object.
- __toString() : string
- Creates a string representation of this object.
- all() : array<string|int, mixed>
- Gets a list of all time zones.
- cast() : TimeZoneInfo
- Makes sure a DateTimeZone inheriting object is a TimeZoneInfo instance.
- compare() : int
- Compares the current instance with another and returns an integer that indicates whether the current object comes before or after or the same position and the other object.
- default() : TimeZoneInfo
- Gets the current default time zone.
- equals() : bool
- Checks whether the current object is equal to another.
- getComments() : string
- Gets location comments for this time zone.
- getCountryCode() : string
- Gets the country code of the country which this time zone falls in.
- getLatitude() : float
- Gets the latitude of this time zone.
- getLocation() : array<string|int, mixed>
- Gets location info for a time zone.
- getLongitude() : float
- Gets the longitude of this time zone.
- getOffset() : int
- Gets the offset of this timezone relative to a given date/time instance.
- jsonSerialize() : mixed
- Returns the data which should be serialized as json.
- setDefault() : void
- Sets the current default time zone.
- utc() : TimeZoneInfo
- Gets a TimeZoneInfo instance representing the UTC (+00:00) time zone.
Methods
__construct()
Constructs a new TimeZoneInfo object.
public
__construct(string $timeZone) : TimeZoneInfo
Parameters
- $timeZone : string
-
Time zone identifier.,
Return values
TimeZoneInfo —New instance of TimeZoneInfo.
__toString()
Creates a string representation of this object.
public
__toString() : string
Return values
string —Representation of this object.
all()
Gets a list of all time zones.
public
static all([bool $ordered = false ][, int $timeZoneGroup = DateTimeZone::ALL ][, string|null $countryCode = null ]) : array<string|int, mixed>
Parameters
- $ordered : bool = false
-
true if the list should be ordered, false if not.
- $timeZoneGroup : int = DateTimeZone::ALL
-
ID of a group to filter the generated list.
- $countryCode : string|null = null
-
Country to filter the generated list by.
Return values
array<string|int, mixed> —Array containing the time zones.
cast()
Makes sure a DateTimeZone inheriting object is a TimeZoneInfo instance.
public
static cast(DateTimeZone $timeZone) : TimeZoneInfo
Parameters
- $timeZone : DateTimeZone
-
Input object.
Return values
TimeZoneInfo —If the input was a TimeZoneInfo, the same instance will be returned. If the input was something else, a new TimeZoneInfo instance will be returned based on the input.
compare()
Compares the current instance with another and returns an integer that indicates whether the current object comes before or after or the same position and the other object.
public
compare(mixed $other) : int
Parameters
- $other : mixed
Return values
int —A value that indicates the relative order of the objects being compared. Less than zero for before, zero for same position, greater than zero for after.
default()
Gets the current default time zone.
public
static default() : TimeZoneInfo
Uses date_default_timezone_get internally.
Return values
TimeZoneInfo —Instance representing the default time zone.
equals()
Checks whether the current object is equal to another.
public
equals(mixed $other) : bool
Parameters
- $other : mixed
Return values
bool —true if the objects are equals, false if not.
getComments()
Gets location comments for this time zone.
public
getComments() : string
Return values
string —Location comments.
getCountryCode()
Gets the country code of the country which this time zone falls in.
public
getCountryCode() : string
Return values
string —Country code for this time zone.
getLatitude()
Gets the latitude of this time zone.
public
getLatitude() : float
Return values
float —Latitude of this time zone.
getLocation()
Gets location info for a time zone.
public
getLocation() : array<string|int, mixed>
It makes more sense to use getCountryCode, getLatitude, getLongitude and getComments, if you can.
Return values
array<string|int, mixed> —Location information.
getLongitude()
Gets the longitude of this time zone.
public
getLongitude() : float
Return values
float —Longitude of this time zone.
getOffset()
Gets the offset of this timezone relative to a given date/time instance.
public
getOffset([DateTimeInterface|null $dateTime = null ]) : int
Parameters
- $dateTime : DateTimeInterface|null = null
-
Date/time to use as a base, null for UTC Now.
Return values
int —Offset relative to given date/time.
jsonSerialize()
Returns the data which should be serialized as json.
public
jsonSerialize() : mixed
Tags
Return values
mixed —Data to be passed to json_encode.
setDefault()
Sets the current default time zone.
public
static setDefault(DateTimeZone|string $timeZone) : void
Uses date_default_timezone_set internally.
Parameters
- $timeZone : DateTimeZone|string
-
Desired default time zone.
Tags
utc()
Gets a TimeZoneInfo instance representing the UTC (+00:00) time zone.
public
static utc() : TimeZoneInfo
Return values
TimeZoneInfo —Instance representing UTC.