PHP | IntlCalendar getTimeZone()函数
IntlCalendar::getTimeZone()函数是PHP中的一个内置函数,用于返回与此日历关联的时区对象。
句法:
- 面向对象风格
IntlTimeZone IntlCalendar::getTimeZone( void )
- 程序风格
IntlTimeZone intlcal_get_time_zone( IntlCalendar $cal )
参数:此函数接受单个参数$cal ,它保存 IntlCalendar 对象的资源。
返回值:此函数返回与此日历关联的 IntlTimeZone 对象。
下面的程序说明了PHP中的 IntlCalendar::getTimeZone()函数:
程序:
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());
?>
输出:
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
)
参考: https://www. PHP.net/manual/en/intlcalendar.gettimezone。 PHP