PHP | IntlCalendar getTimeZone() Function

The IntlCalendar::getTimeZone() function is an inbuilt function in PHP which is used to return the timezone object associated with this calendar.

Syntax:

  • Object oriented style
    IntlTimeZone IntlCalendar::getTimeZone( void )
  • Procedural style
    IntlTimeZone intlcal_get_time_zone( IntlCalendar $cal )

Parameters: This function accepts single parameter $cal which holds the resource of IntlCalendar object.



Return Value: This function returns an IntlTimeZone object associated with this calendar.

Below program illustrates the IntlCalendar::getTimeZone() function in PHP:

Program:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Set the date timezone
ini_set('date.timezone', 'Asia/Calcutta');
ini_set('intl.default_locale', 'en_US');
  
// Create an instance of calendar
$calendar = IntlCalendar::createInstance();
  
// Get the object of timezone 
print_r($calendar->getTimeZone());
  
// Create new IntlGregorianCalendar object
$calendar->setTimezone(new DateTimeZone('Asia/Singapore')); 
  
// Get the object of timezone 
print_r($calendar->getTimeZone());
  
// Set the timezone
$calendar->setTimeZone('GMT+05:30');
  
// Get the object of timezone 
print_r($calendar->getTimeZone());
  
// Set the timezone
$calendar->setTimeZone(IntlTimeZone::getGMT());
  
// Get the object of timezone 
print_r($calendar->getTimeZone());
  
?>

chevron_right


Output:

IntlTimeZone Object
(
    [valid] => 1
    [id] => Asia/Calcutta
    [rawOffset] => 19800000
    [currentOffset] => 19800000
)
IntlTimeZone Object
(
    [valid] => 1
    [id] => Asia/Singapore
    [rawOffset] => 28800000
    [currentOffset] => 28800000
)
IntlTimeZone Object
(
    [valid] => 1
    [id] => GMT+05:30
    [rawOffset] => 19800000
    [currentOffset] => 19800000
)
IntlTimeZone Object
(
    [valid] => 1
    [id] => GMT
    [rawOffset] => 0
    [currentOffset] => 0
)

Reference: https://www.php.net/manual/en/intlcalendar.gettimezone.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.