Open In App

PHP | IntlCalendar getTimeZone() Function

Last Updated : 25 Sep, 2019
Improve
Improve
Like Article
Like
Save
Share
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
  
// 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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads