PHP timezone_transitions_get() Function
The PHP timezone_transitions_get() function returns all transitions for the timezone. This function is an alias of DateTimeZone::getTransitions() method.
Syntax
//Object-oriented style public DateTimeZone::getTransitions(timestampBegin, timestampEnd) //Procedural style timezone_transitions_get(object, timestampBegin, timestampEnd)
Parameters
object |
Required. Procedural style only: A DateTimeZone object returned by timezone_open() function. |
timestampBegin |
Optional. Begin timestamp. |
timestampEnd |
Optional. End timestamp. |
Return Value
Returns a numerically indexed array containing associative array with all transitions on success, or false on failure. The structure of the transition array is as follows:
Key | type | Description |
---|---|---|
ts | Integer | Unix timestamp |
time | String | DateTimeInterface::ISO8601 time string |
offset | Integer | Offset to UTC in seconds |
isdst | Boolean | Whether daylight saving time is active |
abbr | String | Timezone abbreviation |
Example: using Object-oriented style
The example below shows the usage of timezone_transitions_get() method.
<?php //creating a DateTimeZone object $tz = new DateTimeZone("Europe/London"); //setting the transition of $tz $transitions = $tz->getTransitions(); //displaying the array containing all //associative arrays of transitions print_r(array_slice($transitions, 0, 3)); ?>
The output of the above code will be:
Array ( [0] => Array ( [ts] => -9223372036854775808 [time] => -292277022657-01-27T08:29:52+0000 [offset] => -75 [isdst] => [abbr] => LMT ) [1] => Array ( [ts] => -3852662325 [time] => 1847-12-01T00:01:15+0000 [offset] => 0 [isdst] => [abbr] => GMT ) [2] => Array ( [ts] => -1691964000 [time] => 1916-05-21T02:00:00+0000 [offset] => 3600 [isdst] => 1 [abbr] => BST ) )
Example: using Procedural style
The same can be achieved by using the function in procedural style.
<?php //creating a DateTimeZone object $tz = timezone_open("Europe/London"); //setting the transition of $tz $transitions = timezone_transitions_get($tz); //displaying the array containing all //associative arrays of transitions print_r(array_slice($transitions, 0, 3)); ?>
The output of the above code will be:
Array ( [0] => Array ( [ts] => -9223372036854775808 [time] => -292277022657-01-27T08:29:52+0000 [offset] => -75 [isdst] => [abbr] => LMT ) [1] => Array ( [ts] => -3852662325 [time] => 1847-12-01T00:01:15+0000 [offset] => 0 [isdst] => [abbr] => GMT ) [2] => Array ( [ts] => -1691964000 [time] => 1916-05-21T02:00:00+0000 [offset] => 3600 [isdst] => 1 [abbr] => BST ) )
❮ PHP Date and Time Reference