PHP 8.4.0 RC4 available for testing

IntlCalendar::add

(PHP 5 >= 5.5.0, PHP 7, PHP 8, PECL >= 3.0.0a1)

IntlCalendar::addAdd a (signed) amount of time to a field

说明

面向对象风格

public IntlCalendar::add(int $field, int $value): bool

过程化风格

intlcal_add(IntlCalendar $calendar, int $field, int $value): bool

Add a signed amount to a field. Adding a positive amount allows advances in time, even if the numeric value of the field decreases (e.g. when working with years in BC dates).

Other fields may need to adjusted – for instance, adding a month to the 31st of January will result in the 28th (or 29th) of February. Contrary to IntlCalendar::roll(), when a value wraps around, more significant fields may change. For instance, adding a day to the 31st of January will result in the 1st of February, not the 1st of January.

参数

calendar

IntlCalendar 实例。

field

One of the IntlCalendar date/time field constants. These are integer values between 0 and IntlCalendar::FIELD_COUNT.

value

The signed amount to add to the current field. If the amount is positive, the instant will be moved forward; if it is negative, the instant will be moved into the past. The unit is implicit to the field type. For instance, hours for IntlCalendar::FIELD_HOUR_OF_DAY.

返回值

Returns true on success 或者在失败时返回 false.

示例

示例 #1 IntlCalendar::add()

<?php
ini_set
('intl.default_locale', 'fr_FR');
ini_set('date.timezone', 'UTC');

$cal = new IntlGregorianCalendar(2012, 0 /* January */, 31);
echo
IntlDateFormatter::formatObject($cal), "\n";

$cal->add(IntlCalendar::FIELD_MONTH, 1);
echo
IntlDateFormatter::formatObject($cal), "\n";

$cal->add(IntlCalendar::FIELD_DAY_OF_MONTH, 1);
echo
IntlDateFormatter::formatObject($cal), "\n";

以上示例会输出:

31 janv. 2012 00:00:00
29 févr. 2012 00:00:00
1 mars 2012 00:00:00

添加备注

用户贡献的备注

此页面尚无用户贡献的备注。
To Top