博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java LocalDate类| lengthOfMonth()方法与示例
阅读量:2528 次
发布时间:2019-05-11

本文共 2999 字,大约阅读时间需要 9 分钟。

LocalDate类lengthOfMonth()方法 (LocalDate Class lengthOfMonth() method)

  • lengthOfMonth() method is available in java.time package.

    lengthOfMonth()方法在java.time包中可用。

  • lengthOfMonth() method is used to get the length of the month represented by this LocalDate. length of month = No. of days in a month [i.e. 1 to 31]

    lengthOfMonth()方法用于获取此LocalDate表示的月份的长度。 月的长度=一个月中的天数[即1到31]

  • lengthOfMonth() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    lengthOfMonth()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • lengthOfMonth() method does not throw an exception at the time of returning length.

    lengthOfMonth()方法在返回length时不会引发异常。

Syntax:

句法:

public int lengthOfMonth();

Parameter(s):

参数:

  • None

    没有

Return value:

返回值:

The return type of this method is int, it returns the length of month denoted by this object.

此方法的返回类型为int ,它返回此对象表示的月份的长度。

Example:

例:

// Java program to demonstrate the example // of int lengthOfMonth() method of LocalDateimport java.time.*;public class LengthOfMonthOfLocalDate {
public static void main(String args[]) {
// Instantiates three LocalDate LocalDate l_da1 = LocalDate.parse("2007-04-04"); LocalDate l_da2 = LocalDate.now(); LocalDate l_da3 = LocalDate.of(2020, Month.FEBRUARY, 06); // Display l_da1,l_da2 and l_da3 System.out.println("LocalDate l_da1,l_da2 and l_da3: "); System.out.println("l_da1: " + l_da1); System.out.println("l_da2: " + l_da2); System.out.println("l_da3: " + l_da3); System.out.println(); // Here, this method returns the // length of month represented by // this date l_da1 i.e. here // l_da1 = "2007-04-04" then number // of days in the month of april is // 30 i.e. length = 30 int length = l_da1.lengthOfMonth(); // Display length System.out.println("l_da1.lengthOfMonth(): " + length); // Here, this method returns the // length of month represented by // this date l_da2 i.e. here // l_da2 = "2020-05-08" then number // of days in the month of may is // 31 i.e. length = 31 length = l_da2.lengthOfMonth(); // Display length System.out.println("l_da2.lengthOfMonth(): " + length); // Here, this method returns the // length of month represented by // this date l_da3 i.e. here // l_da3 = "2020-02-06" then number // of days in the month of feb is // either 28 or 29 based on year // i.e. 2020 is a leap year so the // number of days in feb is 29 i.e. // length = 29 length = l_da3.lengthOfMonth(); // Display length System.out.println("l_da3.lengthOfMonth(): " + length); }}

Output

输出量

LocalDate l_da1,l_da2 and l_da3: l_da1: 2007-04-04l_da2: 2020-05-31l_da3: 2020-02-06l_da1.lengthOfMonth(): 30l_da2.lengthOfMonth(): 31l_da3.lengthOfMonth(): 29

翻译自:

转载地址:http://vwvzd.baihongyu.com/

你可能感兴趣的文章
sql语言的一大类 DML 数据的操纵语言
查看>>
VMware黑屏解决方法
查看>>
JS中各种跳转解析
查看>>
JAVA 基础 / 第八课:面向对象 / JAVA类的方法与实例方法
查看>>
Ecust OJ
查看>>
P3384 【模板】树链剖分
查看>>
Thrift源码分析(二)-- 协议和编解码
查看>>
考勤系统之计算工作小时数
查看>>
4.1 分解条件式
查看>>
Equivalent Strings
查看>>
flume handler
查看>>
收藏其他博客园主写的代码,学习加自用。先表示感谢!!!
查看>>
H5 表单标签
查看>>
su 与 su - 区别
查看>>
C语言编程-9_4 字符统计
查看>>
在webconfig中写好连接后,在程序中如何调用?
查看>>
限制用户不能删除SharePoint列表中的条目(项目)
查看>>
【Linux网络编程】使用GDB调试程序
查看>>
feign调用spring clound eureka 注册中心服务
查看>>
RotateCard(自定义旋转view)
查看>>