Open In App

PHP | IntlCalendar setTimeZone() Function

The IntlCalendar::setTimeZone() function is an inbuilt function in PHP which is used to set the new timezone for this calendar. The time is represented in terms of object and it preserves to the detriment of the timezone field values.

Syntax:



Parameters: This function uses two parameters as mentioned above and described below:

Return Value: This function returns TRUE on success and FALSE on failure.



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

Program:




<?php
  
// Set the date timezone
ini_set('date.timezone', 'Asia/Calcutta');
  
// Create a DateTime object
$calendar = IntlCalendar::fromDateTime('2019-03-21 09:19:29');
  
// Format the DateTime object 
echo IntlDateFormatter::formatObject($calendar, IntlDateFormatter::FULL), "\n";
  
// Create new IntlGregorianCalendar object
$calendar->setTimezone(new DateTimeZone('Asia/Singapore')); 
  
// Format the DateTime object 
echo IntlDateFormatter::formatObject($calendar, IntlDateFormatter::FULL), "\n";
  
// Set the timezone
$calendar->setTimeZone('GMT+05:30');
  
// Format the DateTime object 
echo IntlDateFormatter::formatObject($calendar, IntlDateFormatter::FULL), "\n";
  
// Set the timezone
$calendar->setTimeZone(IntlTimeZone::getGMT());
  
// Format the DateTime object 
echo IntlDateFormatter::formatObject($calendar, IntlDateFormatter::FULL);
  
?>

Output:
Thursday, March 21, 2019 at 9:19:29 AM India Standard Time
Thursday, March 21, 2019 at 11:49:29 AM Singapore Standard Time
Thursday, March 21, 2019 at 9:19:29 AM GMT+05:30
Thursday, March 21, 2019 at 3:49:29 AM GMT

Reference: https://www.php.net/manual/en/intlcalendar.settimezone.php

Article Tags :