Tutorialspoint.dev

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:

<?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));
?>

/div>
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:

<?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));
?>

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



This article is attributed to GeeksforGeeks.org

You Might Also Like

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter