当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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–



相关用法


注:本文由纯净天空筛选整理自Kirti_Mangal大神的英文原创作品 ChronoLocalDate lengthOfMonth() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。