Java 中的 LocalDate lengthOfMonth() 方法
特定 LocalDate 中的月份长度可以使用 Java 中 LocalDate 类中的 lengthOfMonth() 方法获得。此方法不需要参数,它返回特定 LocalDate 中月份的长度,即 28、29、30 或 31。
演示此方法的程序如下 −
示例
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 month is: " + ld.lengthOfMonth());
}
}输出
The LocalDate is: 2019-02-15 The length of the month is: 28
现在让我们了解一下上面的程序。
首先显示 LocalDate。然后使用 lengthOfMonth() 方法获取 LocalDate 中月份的长度并显示。演示此操作的代码片段如下 −
LocalDate ld = LocalDate.parse("2019-02-15");
System.out.println("The LocalDate is: " + ld);
System.out.println("The length of the month is: " + ld.lengthOfMonth());
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP