Java ChronoLocalDate lengthOfYear()方法及实例
Java中ChronoLocalDate接口的lengthOfYear()方法返回该日期所代表的年份的长度。
语法:
public int lengthOfYear()
参数 :该方法不接受参数。
返回值 :如果是闰年,该函数返回 366 ,否则返回 365 。
以下程序说明了Java中ChronoLocalDate的 lengthOfYear() 方法。
程序1 :
// Program to illustrate the lengthOfYear() method import java.util.*;import java.time.*;import java.time.chrono.*; public class GfG { public static void main(String[] args) { // Parses the date ChronoLocalDate dt1 = LocalDate.parse("2018-11-27"); // Get the length of the year System.out.println(dt1.lengthOfYear()); }}
输出。
365
程序2 :
// Program to illustrate the lengthOfYear() method import java.util.*;import java.time.*;import java.time.chrono.*; public class GfG { public static void main(String[] args) { // Parses the date ChronoLocalDate dt1 = LocalDate.parse("2016-11-27"); // Get the length of the year System.out.println(dt1.lengthOfYear()); }}输出。
366
参考资料 : https://docs.oracle.com/javase/9/docs/api/java/time/chrono/ChronoLocalDate.html#lengthOfYear-
