Php/docs/intlcalendar.islenient

来自菜鸟教程
跳转至:导航、​搜索

IntlCalendar::isLenient

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

IntlCalendar::isLenientWhether date/time interpretation is in lenient mode


说明

面向对象风格

public IntlCalendar::isLenient ( ) : bool

过程化风格

intlcal_is_lenient ( IntlCalendar $cal ) : bool

Returns whether the current date/time interpretations is lenient (the default). If that is case, some out of range values for fields will be accepted instead of raising an error.


参数

cal
The IntlCalendar resource.


返回值

A bool representing whether the calendar is set to lenient mode.


范例

Example #1 IntlCalendar::isLenient()

<?phpini_set('date.timezone', 'Europe/Lisbon');ini_set('intl.default_locale', 'pt_PT');ini_set('intl.use_exceptions', '1');$cal = new IntlGregorianCalendar(2013, 6 /* July */, 1);var_dump(IntlDateFormatter::formatObject($cal), // 01/07/2013, 00:00:00$cal->isLenient()); // true$cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 33);var_dump(IntlDateFormatter::formatObject($cal)); // 02/08/2013, 00:00:00$cal->setLenient(false);var_dump($cal->isLenient()); // false$cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, 33);var_dump(IntlDateFormatter::formatObject($cal)); // error

以上例程会输出:


string(20) "01/07/2013, 00:00:00"
bool(true)
string(20) "02/08/2013, 00:00:00"
bool(false)

Fatal error: Uncaught exception 'IntlException' with message 'datefmt_format_object: error obtaining instant from IntlCalendar' in /home/foobar/example.php:16
Stack trace:
#0 /home/foobar/example.php(16): IntlDateFormatter::formatObject(Object(IntlGregorianCalendar))
#1 {main}
  thrown in /home/foobar/example.php on line 16