IntlCalendar::roll()函数是PHP中的内置函数,用于在不增加更重要字段的情况下为字段增加值。 IntlCalendar::roll(函数与IntlCalendar::add(函数之间的区别是IntlCalendar::roll(函数的字段值溢出,不会影响到更重要的字段。
用法:
面向对象的风格bool IntlCalendar::roll( int $field, mixed $amountOrUpOrDown )
程序风格bool intlcal_roll( IntlCalendar $cal, int $field, mixed $amountOrUpOrDown )
参数:
$cal:此参数保存IntlCalendar对象的资源。
$field:此参数保存IntlCalendar日期/时间字段常量之一。字段常量的值是整数,介于0到IntlCalendar::FIELD_COUNT之间。
$amountOrUpOrDown:此参数保存要添加到该字段的签名数量。 TRUE值表示向上滚动(加1),而FALSE值表示向下滚动(减1)。
返回值:如果成功,则此函数返回TRUE;如果失败,则返回FALSE。
以下示例程序旨在说明PHP中的IntlCalendar::roll()函数:
程序:
// Set the DateTime zone
ini_set('date.timezone', 'Asia/Calcutta');
// Create an instance of IntlCalendar
$calendar = IntlCalendar::createInstance('Asia/Calcutta');
// Set the DateTime to the calendar object
$calendar->set(2019, 8, 24);
// Display the calendar object
var_dump(IntlDateFormatter::formatObject($calendar));
// Roll down 1 day of date field
$calendar->roll(IntlCalendar::FIELD_DAY_OF_MONTH, false);
// Display the calendar object
var_dump(IntlDateFormatter::formatObject($calendar));
?>
输出:
string(24) "Sep 24, 2019, 8:29:48 AM"
string(24) "Sep 23, 2019, 8:29:48 AM"