Java ChronoLocalDate lengthOfMonth()方法及示例
Java中 ChronoLocalDate 接口的 lengthOfMonth() 方法返回该日期所代表的月份的长度。
语法:
public int lengthOfMonth()
参数 :该方法不接受参数。
返回值 :该函数返回以天为单位的月份长度。
以下程序说明了Java中ChronoLocalDate的 lengthOfMonth() 方法。
程序1 :
// Program to illustrate the lengthOfMonth() method import java.util.*;import java.time.*;import java.time.chrono.*; public class GfG { public static void main(String[] args) { // Parse the date ChronoLocalDate dt1 = LocalDate.parse("2018-11-27"); // Get the length of the month System.out.println(dt1.lengthOfMonth()); }}
输出。
30
程序2 :
// Program to illustrate the lengthOfMonth() 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-01-27"); // Get the length of the month System.out.println(dt1.lengthOfMonth()); }}输出。
31
参考资料 : https://docs.oracle.com/javase/9/docs/api/java/time/chrono/ChronoLocalDate.html#lengthOfMonth-
