The TimeZone class provides access to time zone functionality.
TimeZone objects based on zoneinfo region files can have daylight savings time information; those based on UTC offsets have none.
Table 4.553. TimeZone Method Overview
Method | Except? | Description |
|---|---|---|
|
| Y | Creates the TimeZone object based on the region name (ex: "America/Chicago") or the number of seconds east of UTC (3600 = UTC +01). |
N | Destroys the TimeZone object. | |
N | Creates a copy of the TimeZone object. | |
N | Returns the number of seconds east of UTC for the zone; negative numbers indicate a zone west of UTC. | |
N | Returns | |
N | Returns the region name as a string; if the current zone is based on a UTC offset, then the UTC offset is returned as a string like "+01:00". | |
|
| N | Returns the equivalent date in the current time zone; when using integer arguments, offsets are in seconds and microseconds from 1970-01-01Z. |
|
| N | Returns a date in the object's zone based on an offset in milliseconds from 1970-01-01Z. |
|
| N | Returns a date in the object's zone based on an offset in microseconds from 1970-01-01Z. |
|
| N | Returns the default time zone for the current execution context. |
|
| N | Sets the default time zone for the current execution context. |
|
| N | Sets the default time zone for the current execution context based on the number of seconds east of UTC; for zones west of UTC, use negative numbers. |
|
| Y | Sets the default time zone for the current execution context from a zoneinfo region file; if there are errors reading or parsing the file, an exception is thrown. |
Creates the TimeZone object based on the region name (ex: "America/Chicago") or the UTC offset passed as the number of seconds east of UTC for the zone.
TimeZone::constructor(string $region)
TimeZone::constructor(softint $secs_east)
my TimeZone $tz("Europe/Prague");
Table 4.555. Exceptions Thrown by TimeZone::constructor()
err | desc |
|---|---|
| Unable to read zoneinfo file; invalid file magic; error parsing zoneinfo file, etc |
Creates a copy of the TimeZone object.
my TimeZone $newzone = $tz.copy();
Returns the number of seconds east of UTC for the zone; negative numbers indicate a zone west of UTC.
my int $offset = $tz.UTCOffset();
Table 4.556. Return Values for TimeZone::UTCOffset()
|
Return Type |
Description |
|---|---|
|
Returns the number of seconds east of UTC for the zone; negative numbers indicate a zone west of UTC. |
Returns True if the current zone has daylight saving's time rules, False if not. TimeZone objects based on zoneinfo region files can have (but do not necessarily have) daylight savings time information; those based on UTC offsets have none.
my bool $hasdst = $tz.hasDST();
Table 4.557. Return Values for TimeZone::hasDST()
|
Return Type |
Description |
|---|---|
Returns |
Returns the region name as a string; if the current zone is based on a UTC offset, then the UTC offset is returned as a string like "+01:00".
my string $region = $tz.region();
Table 4.558. Return Values for TimeZone::region()
|
Return Type |
Description |
|---|---|
Returns the region name as a string; if the current zone is based on a UTC offset, then the UTC offset is returned as a string like "+01:00". |
Returns the equivalent date in the current time zone; when using integer arguments, offsets are in seconds and microseconds from 1970-01-01Z.
date TimeZone::date(softint $secs, softint $us = 0)
date TimeZone::date(date $date)
my date $dt = $tz.date($other);
Table 4.560. Return Values for TimeZone::date()
|
Return Type |
Description |
|---|---|
Returns the equivalent date in the current time zone; when using integer arguments, offsets are in seconds and microseconds from 1970-01-01Z. |
Returns a date in the object's zone based on an offsets in milliseconds from 1970-01-01Z.
date TimeZone::dateMs(softint $ms)
my date $dt = $tz.dateMs($ms);
Table 4.561. Return Values for TimeZone::dateMs()
|
Return Type |
Description |
|---|---|
Returns a date in the object's zone based on an offsets in milliseconds from 1970-01-01Z. |
Returns a date in the object's zone based on an offset in microseconds from 1970-01-01Z.
date TimeZone::dateUs(softint $us)
my date $dt = $tz.dateUs($us);
Table 4.562. Return Values for TimeZone::dateUs()
|
Return Type |
Description |
|---|---|
Returns a date in the object's zone based on an offset in microseconds from 1970-01-01Z. |
Returns the default time zone for the current execution context.
static TimeZoneTimeZone::get()
my TimeZone $tz = TimeZone::get();
Table 4.563. Return Values for TimeZone::get()
|
Return Type |
Description |
|---|---|
Returns the default time zone for the current execution context. |
Sets the default time zone for the current execution context.
See also Program::setTimeZone().
static nothing TimeZone::set(TimeZone $zone)
TimeZone::set($zone);
Table 4.564. Arguments for TimeZone::set()
Argument | Description |
|---|---|
| The default time zone to set for the current execution context. |
Sets the default time zone for the current execution context based on the number of seconds east of UTC; for zones west of UTC, use negative numbers.
Time zones set with this method cannot have any daylight savings time information; to set a zone with daylight savings time information, use TimeZone::setRegion() instead.
See also Program::setTimeZoneUTCOffset().
static nothing TimeZone::setUTCOffset(softint $secs_east)
The following examples are all equivalent, setting the time zone to +02 UTC:
TimeZone::setUTCOffset(7200);
TimeZone::setUTCOffset(2h);
TimeZone::setUTCOffset(PT2H);
Table 4.565. Arguments for TimeZone::setUTCOffset()
Argument | Description |
|---|---|
| The number of seconds east of UTC; for zones west of UTC, use negative numbers |
Sets the default time zone for the current execution context from a zoneinfo region file; if there are errors reading or parsing the file, an exception is thrown.
See also Program::setTimeZoneRegion().
static nothing TimeZone::setRegion(string $region)
TimeZone::setRegion("Europe/Prague");
Not available with PO_NO_LOCALE_CONTROL
Table 4.566. Arguments for TimeZone::setRegion()
Argument | Description |
|---|---|
| The region name for the time zone (ex: "America/Chicago"); if the zoneinfo file for the region cannot be found or parsed, then an exception is thrown. |
Table 4.567. Exceptions Thrown by TimeZone::setRegion()
err | desc |
|---|---|
| Unable to read zoneinfo file; invalid file magic; error parsing zoneinfo file, etc |