Java中的YearMonth類的lengthOfYear()方法用於返回此year-month對象的天數的天數長度。根據年份是否為leap年,年份的長度值為365或366。
用法:
public int lengthOfYear()
參數:此方法不接受任何參數。
返回值:它返回一個整數值,以天數表示年份的長度。
以下程序說明了Java中YearMonth的lengthOfYear()方法:
示例1::
// Program to illustrate the lengthOfYear() method
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
// Create YearMonth object
YearMonth yearMonth = YearMonth.of(2016, 2);
// Print the length of year in Number
// of days, 366 in this case as 2016 is
// a Leap Year
System.out.println(yearMonth.lengthOfYear());
}
}
示例2::
// Program to illustrate the lengthOfYear() method
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
// Create YearMonth object
YearMonth yearMonth = YearMonth.of(1990, 2);
// Print the length of year in Number
// of days, 365 in this case as 1990 is
// not a Leap Year
System.out.println(yearMonth.lengthOfYear());
}
}
參考: https://docs.oracle.com/javase/8/docs/api/java/time/YearMonth.html#lengthOfYear-
相關用法
- Java LocalDate lengthOfYear()用法及代碼示例
- Java ChronoLocalDate lengthOfYear()用法及代碼示例
- Java YearMonth with()用法及代碼示例
- Java YearMonth until()用法及代碼示例
- Java YearMonth withMonth()用法及代碼示例
- Java YearMonth isValidDay()用法及代碼示例
- Java YearMonth withYear()用法及代碼示例
- Java YearMonth plus(TemporalAmount)用法及代碼示例
- Java YearMonth isLeapYear()用法及代碼示例
- Java YearMonth isAfter()用法及代碼示例
- Java YearMonth range()用法及代碼示例
- Java YearMonth isBefore()用法及代碼示例
- Java YearMonth query()用法及代碼示例
- Java YearMonth isSupported(TemporalUnit)用法及代碼示例
- Java YearMonth minus(TemporalAmount)用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 YearMonth lengthOfYear() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。