PHP | IntlCalendar setTimeZone()函数
IntlCalendar::setTimeZone()函数是PHP中的一个内置函数,用于设置此日历的新时区。时间以对象的形式表示,它保留不利于时区字段值。
句法:
- 面向对象风格
bool IntlCalendar::setTimeZone( mixed $timeZone )
- 程序风格
bool intlcal_set_time_zone( IntlCalendar $cal, mixed $timeZone )
参数:此函数使用上面提到的两个参数,如下所述:
- $cal:此参数保存 IntlCalendar 的资源。
- $timeZone:此参数保存此日历使用的新时区。
- NULL:将使用默认时区。
- IntlTimeZone:直接使用。
- DateTimeZone:将提取 DateTimeZone 对象的标识符,并创建一个 ICU 时区对象。
- 字符串:它应该是一个有效的 ICU 时区标识符。
返回值:此函数在成功时返回 TRUE,在失败时返回 FALSE。
下面的程序说明了PHP中的 IntlCalendar::setTimeZone()函数:
程序:
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);
?>
输出:
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
参考: https://www. PHP.net/manual/en/intlcalendar.settimezone。 PHP