Open In App

PHP | IntlCalendar getTimeZone() Function

Last Updated : 25 Sep, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
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: php
<?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());

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

Next Article

Similar Reads