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:
- Object oriented style
bool IntlCalendar::setTimeZone( mixed $timeZone )
- Procedural style
bool intlcal_set_time_zone( IntlCalendar $cal, mixed $timeZone )
Parameters: This function uses two parameters as mentioned above and described below:
- $cal: This parameter holds the resource of IntlCalendar.
- $timeZone: This parameter holds the new timezone which is used by this calendar.
- NULL: The default timezone will be used.
- IntlTimeZone: It is used directly.
- DateTimeZone: The identifier of DateTimeZone object will be extracted and an ICU timezone object will be created.
- string: It should be a valid ICU timezone identifier.
Return Value: This function returns TRUE on success and FALSE on failure.
Below program illustrates the IntlCalendar::setTimeZone() function in PHP:
Program:
<?php
ini_set ( 'date.timezone' , 'Asia/Calcutta' );
$calendar = IntlCalendar::fromDateTime( '2019-03-21 09:19:29' );
echo IntlDateFormatter::formatObject( $calendar , IntlDateFormatter::FULL), "\n" ;
$calendar ->setTimezone( new DateTimeZone( 'Asia/Singapore' ));
echo IntlDateFormatter::formatObject( $calendar , IntlDateFormatter::FULL), "\n" ;
$calendar ->setTimeZone( 'GMT+05:30' );
echo IntlDateFormatter::formatObject( $calendar , IntlDateFormatter::FULL), "\n" ;
$calendar ->setTimeZone(IntlTimeZone::getGMT());
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
Last Updated :
25 Sep, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...