PHP | timezone_transitions_get() Function

PHP timezone_transitions_get() Function


Hello folks! welcome back to a new edition of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP timezone_transitions_get() Function.

The timezone_transitions_get() function is an alias of DateTimeZone::_getTransitions(). This php function accepts a DateTimeZone object as parameter and returns transitions for the given timezone.

Syntax

Following below is the syntax to use this function -

timezone_transitions_get($object, $timestamp_start, $timestamp_end)


Parameter Details

Sr.NoParameter & Description
1

object (Mandatory)

This is a DateTimeZone object.

2

timestamp_start (Optional)

An integer value representing the begin timestamp.

3

timestamp_end (Optional)

An integer value representing the end timestamp.


Return Value

This PHP function returns all the transitions in form of an array. In case of a failure this function returns the boolean value false.

PHP Version

This PHP function was first introduced as part of core PHP v 5.2.0 and, it works with all the later versions.

Example1

Below example shows the usage of PHP timezone_transitions_get() function -

<?php
   $tz = new DateTimeZone("Indian/Mahe");
   $list = timezone_transitions_get($tz);
   print_r($list);
?>

Output

When the above code is executed, it will produce the following result -

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

    [1] => Array
        (
            [ts] => -2006653308
            [time] => 1906-05-31T20:18:12+0000
            [offset] => 14400
            [isdst] =>
            [abbr] => +04
        )

    [2] => Array
        (
            [ts] => 2147483647
            [time] => 2038-01-19T03:14:07+0000
            [offset] => 14400
            [isdst] =>
            [abbr] => +04
        )

)

Example2

Try the following example -

$timezone = new DateTimeZone("CET");
print_r(reset($timezone->getTransitions()));
   
echo"------------------------------------------------\n";
   
print_r( reset( timezone_transitions_get ($timezone) ) );

Output

When the above code is executed, it will produce the following result -

Array (
   [ts] => -1693706400
   [time] => 1916-04-30T22:00:00+0000
   [offset] => 7200
   [isdst] => 1
   [abbr] => CEST
)
------------------------------------------------
Array (
   [ts] => -1693706400
   [time] => 1916-04-30T22:00:00+0000
   [offset] => 7200
   [isdst] => 1
   [abbr] => CEST
)


Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the PHP date_add Function.

Do feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.