Java month minLength()方法

来源:这里教程网 时间:2026-02-17 20:57:43 作者:

Java month minLength()方法

minLength() 方法是Month ENUM的一个内置方法,用来获取这个月的最小长度(天数)。例如,二月可以有28天和29天,这取决于今年是否是闰年。因此,这个方法将返回2月的28天,因为2月的最小天数是29天。

语法:

public int minLength()

参数 :该方法不接受任何参数。

返回值 :该方法返回该月的最小长度(以天数计)。

以下程序说明了上述方法。

程序1 :

import java.time.*;import java.time.Month;import java.time.temporal.ChronoField;  class monthEnum {    public static void main(String[] args)    {        // Create a month instance        Month month = Month.FEBRUARY;          // Print the minimum length of this Month        System.out.println(month.minLength());    }}

输出。

28

程序2 :

import java.time.*;import java.time.Month;import java.time.temporal.ChronoField;  class monthEnum {    public static void main(String[] args)    {        // Create a month instance        Month month = Month.MAY;          // Print the min length of this Month        System.out.println(month.minLength());    }}

输出。

31

参考资料 : https://docs.oracle.com/javase/8/docs/api/java/time/Month.html#minLength-

相关推荐