maxLength()方法是月份ENUM的內置方法,用於獲取本月的最大天數。例如,根據今年是否為leap年,二月可以同時具有28天和29天。因此,此方法將返回2月的29,因為2月中的最大天數是29。
用法:
public int maxLength()
參數:此方法不接受任何參數。
返回值:此方法返回該月的最大長度(以天數表示)。
以下示例程序旨在說明上述方法:
程序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 maximum length of this Month
System.out.println(month.maxLength());
}
}
輸出:
29
程序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 max length of this Month
System.out.println(month.maxLength());
}
}
輸出:
31
參考: https://docs.oracle.com/javase/8/docs/api/java/time/Month.html#maxLength–
相關用法
- Java Year atMonth(Month month)用法及代碼示例
- Java Month plus()用法及代碼示例
- Java Month get()用法及代碼示例
- Java Month of()用法及代碼示例
- Java Month from()用法及代碼示例
- Java Month adjustInto()用法及代碼示例
- Java Month firstDayOfYear()用法及代碼示例
- Java Month length()用法及代碼示例
- Java Month minLength()用法及代碼示例
- Java Month getValue()用法及代碼示例
- Java Month minus()用法及代碼示例
- Java Month isSupported()用法及代碼示例
- Java Month getLong()用法及代碼示例
- Java Month getDisplayName()用法及代碼示例
- Java Month firstMonthOfQuarter()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 Month maxLength() method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。