PHP | timezone_transitions_get() Function

The timezone_transitions_get() function is an inbuilt function in PHP which is used to returns all transitions for the timezone. This function returns an array containing associative array of all transitions on success or False on failure.

Syntax:

  • Procedural style:
    timezone_transitions_get( $object, $timestamp_begin, $timestamp_end )
  • Object oriented style:
    DateTimeZone::getTransitions( $timestamp_begin, $timestamp_end )

Parameters: This function accepts three parameters as mentioned above and described below:



  • $object: It is a mandatory parameter which is used to specify the DateTime object which is returned by the date_create() function.
  • $timestamp_begin: This parameter is used to set begin timestamp.
  • $timestamp_end: This parameter is used to set end timestamp.

Return Value: This function returns an array containing associative array with all transitions on success or False on failure.

Below programs illustrate the timezone_transitions_get() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
   
// Set time_zone object
$time_zone = timezone_open('Asia/Kolkata');
   
// Set the transition of time_zone
$transition = timezone_transitions_get( $time_zone );
  
// Display an array containing associative
// array of all transition
print_r(array_slice($transition, 0, 3));
?>

chevron_right


Output:

Array
(
    [0] => Array
        (
            [ts] => -9223372036854775808
            [time] => -292277022657-01-27T08:29:52+0000
            [offset] => 21200
            [isdst] => 
            [abbr] => HMT
        )

    [1] => Array
        (
            [ts] => -2147483648
            [time] => 1901-12-13T20:45:52+0000
            [offset] => 19270
            [isdst] => 
            [abbr] => MMT
        )

    [2] => Array
        (
            [ts] => -2019705670
            [time] => 1905-12-31T18:38:50+0000
            [offset] => 19800
            [isdst] => 
            [abbr] => IST
        )

)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Set time_zone object
$timezone = new DateTimeZone("Asia/Kolkata");
  
// Set the transition of time_zone
$transition = $timezone->getTransitions();
  
// Display an array containing associative
// array of all transition
print_r(array_slice($transition, 0, 3));
?>

chevron_right


Output:

Array
(
    [0] => Array
        (
            [ts] => -9223372036854775808
            [time] => -292277022657-01-27T08:29:52+0000
            [offset] => 21200
            [isdst] => 
            [abbr] => HMT
        )

    [1] => Array
        (
            [ts] => -2147483648
            [time] => 1901-12-13T20:45:52+0000
            [offset] => 19270
            [isdst] => 
            [abbr] => MMT
        )

    [2] => Array
        (
            [ts] => -2019705670
            [time] => 1905-12-31T18:38:50+0000
            [offset] => 19800
            [isdst] => 
            [abbr] => IST
        )

)

Related Articles:

Reference: http://php.net/manual/en/datetimezone.gettransitions.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.