📜  PHP | IntlCalendar getLeastMaximum()函数(1)

📅  最后修改于: 2023-12-03 14:45:17.950000             🧑  作者: Mango

PHP | IntlCalendar getLeastMaximum()函数

介绍

IntlCalendar getLeastMaximum()函数是PHP IntlCalendar类中的一个方法,用于返回日历的某个字段的最小最大值。最小最大值指的是在该字段的最大值和最小值之间,最小的值是多少。

语法
public int IntlCalendar::getLeastMaximum ( int $field )
参数

field: 日历字段。可选值为IntlCalendar类中的常量之一。

| 常量名 | 描述 | | --- | --- | | IntlCalendar::FIELD_ERA | 它表示 ERA 字段 | | IntlCalendar::FIELD_YEAR | 它表示 YEAR 字段 | | IntlCalendar::FIELD_MONTH | It represents the MONTH field | | IntlCalendar::FIELD_WEEK_OF_YEAR | It represents the WEEK_OF_YEAR field | | IntlCalendar::FIELD_WEEK_OF_MONTH | It represents the WEEK_OF_MONTH field | | IntlCalendar::FIELD_DAY_OF_MONTH | It represents the DAY_OF_MONTH field | | IntlCalendar::FIELD_DAY_OF_YEAR | It represents the DAY_OF_YEAR field | | IntlCalendar::FIELD_DAY_OF_WEEK | It represents the DAY_OF_WEEK field | | IntlCalendar::FIELD_DAY_OF_WEEK_IN_MONTH | It represents the DAY_OF_WEEK_IN_MONTH field | | IntlCalendar::FIELD_AM_PM | It represents the AM_PM field | | IntlCalendar::FIELD_HOUR | It represents the HOUR field | | IntlCalendar::FIELD_HOUR_OF_DAY | It represents the HOUR_OF_DAY field | | IntlCalendar::FIELD_MINUTE | It represents the MINUTE field | | IntlCalendar::FIELD_SECOND | It represents the SECOND field | | IntlCalendar::FIELD_MILLISECOND | It represents the MILLISECOND field | | IntlCalendar::FIELD_ZONE_OFFSET | It represents the ZONE_OFFSET field | | IntlCalendar::FIELD_DST_OFFSET | It represents the DST_OFFSET field | | IntlCalendar::FIELD_YEAR_WOY | It represents the YEAR_WOY field | | IntlCalendar::FIELD_DOW_LOCAL | It represents the DOW_LOCAL field | | IntlCalendar::FIELD_EXTENDED_YEAR | It represents the EXTENDED_YEAR field | | IntlCalendar::FIELD_JULIAN_DAY | It represents the JULIAN_DAY field | | IntlCalendar::FIELD_MILLISECONDS_IN_DAY | It represents the MILLISECONDS_IN_DAY field | | IntlCalendar::FIELD_IS_LEAP_MONTH | It represents the IS_LEAP_MONTH field |

返回值

该函数返回一个整数,表示最小最大值。

示例

以下代码示例演示了如何使用IntlCalendar getLeastMaximum()函数获取当前月份的最小最大值。

$cal = IntlCalendar::createInstance();
$cal->set(IntlCalendar::FIELD_MONTH, 5); // set month to May
$leastMax = $cal->getLeastMaximum(IntlCalendar::FIELD_DAY_OF_MONTH); // get least maximum value for DAY_OF_MONTH
echo $leastMax; // output: 1

在上面的代码示例中,我们使用IntlCalendar::createInstance()方法创建一个IntlCalendar对象。然后,我们使用$cal->set()方法将日历的FIELD_MONTH字段设置为5,即5月份。最后,我们使用$cal->getLeastMaximum()方法获取该月份天数的最小最大值。由于5月份的最小天数为1,所以$leastMax变量的值为1。

参考文献