Java 中的 LocalDate 日期类 lengthOfYear() 方法
可以使用 Java 中 LocalDate 类的 lengthOfYear() 方法,获取特定 LocalDate 中的年份长度。此方法不需要参数,它返回特定 LocalDate 中的年份长度,即普通年份为 365 天,闰年为 366 天。
演示此方法的程序如下 −
示例
import java.time.*;
public class Main {
public static void main(String[] args) {
LocalDate ld = LocalDate.parse("2019-02-15");
System.out.println("The LocalDate is: " + ld);
System.out.println("The length of the year is: " + ld.lengthOfYear());
}
}输出
The LocalDate is: 2019-02-15 The length of the year is: 365
现在,让我们理解一下上面的程序。
首先,显示 LocalDate。然后,使用 lengthOfYear() 方法获取 LocalDate 中的年份长度并显示。演示此过程的代码片段如下 −
LocalDate ld = LocalDate.parse("2019-02-15");
System.out.println("The LocalDate is: " + ld);
System.out.println("The length of the year is: " + ld.lengthOfYear());
广告
数据结构
计算机网络
关系型数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
JavaScript
PHP