Java LocalDate类| lengthOfYear()方法和示例

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

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

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

  • lengthOfYear() method is used to get the length of the year represented by this LocalDate.

    lengthOfYear()方法用于获取此LocalDate表示的年份的长度。

    length of year = No. of days in a year [i.e. 1 to 365 (for a non-leap year) or 366 (for leap year)].

    年的长度=一年中的天数[即1到365(对于非-年)或366(对于leap年)]。

  • lengthOfYear() 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.

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

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

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

Syntax:

句法:

    public int lengthOfYear();

Parameter(s):

参数:

  • None

    没有

Return value:

返回值:

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

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

Example:

例:

// Java program to demonstrate the example 
// of int lengthOfYear() method of LocalDate
import java.time.*;
public class LengthOfYearOfLocalDate {
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(2008, 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 year represented by this date
// l_da1 i.e. here l_da1 = "2007-04-04"
// then number of days in the year 2007 is
// 365 i.e. length = 365
int length = l_da1.lengthOfYear();
// Display length
System.out.println("l_da1.lengthOfYear(): " + length);
// Here, this method returns the length of
// year represented by this date
// l_da2 i.e. here l_da2 = "2020-05-08" 
// then number of days in the year 2020
// is 366 i.e. length = 366
length = l_da2.lengthOfYear();
// Display length
System.out.println("l_da2.lengthOfYear(): " + length);
// Here, this method returns the length of
// year represented by this date
// l_da3 i.e. here l_da3 = "2008-02-06" 
// then number of days in the year 2008 
// is 366 i.e. length = 366
length = l_da3.lengthOfYear();
// Display length
System.out.println("l_da3.lengthOfYear(): " + length);
}
}

Output

输出量

LocalDate l_da1,l_da2 and l_da3: 
l_da1: 2007-04-04
l_da2: 2020-06-02
l_da3: 2008-02-06l_da1.lengthOfYear(): 365
l_da2.lengthOfYear(): 366
l_da3.lengthOfYear(): 366

翻译自: https://www.includehelp.com/java/localdate-lengthofyear-method-with-example.aspx

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/545265.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

23张图!万字详解「链表」,从小白到大佬!

作者 | 王磊来源 | Java中文社群(ID:javacn666)转载请联系授权(微信ID:GG_Stone)链表和数组是数据类型中两个重要又常用的基础数据类型。数组是连续存储在内存中的数据结构,因此它的优势是可以通…

何为“秒传”

写在前面 最近一直在弄文件传输的组件,在讨论组里面,有同事提到“秒传”的功能。在目前的通信软件中也有网盘的功能,就从网上搜了一下,这里对“秒传”的实现思路做一下总结,在之后会写一个小的demo实现一下。没有其他&…

JavaScript入门

JavaScript入门1_语法基础1.1_变量1.2_数据类型1.3_运算符1.4_类型转换1.5_注释跟c一样2_流程控制语句3_函数3.1_没有返回值的函数3.2_有返回值的函数4_对象4.1_对象简介4.2_字符串对象4.3_数组对象4.4_时间对象4.5_数学对象简介5_DOM基础5.1_DOM是什么5.2_节点类型5.3_获取元素…

oracle 序列的概念与使用步骤

转载自:http://www.worlduc.com/blog2012.aspx?bid20342458 一、概念 1、 序列: 是oacle提供的用于产生一系列唯一数字的数据库对象。主要用于提供主键值。 2、 创建序列: 创建序列的语法 CREATE SEQUENCE sequence //创建序列名称 [INCREMENT BY n]…

数组转List的3种方法和使用对比!

作者 | 大脑补丁来源 | blog.csdn.net/x541211190/article/details/79597236前言:本文介绍Java中数组转为List三种情况的优劣对比,以及应用场景的对比,以及程序员常犯的类型转换错误原因解析。一.最常见方式(未必最佳)…

java 根据类名示例化类_Java即时类| getEpochSecond()方法与示例

java 根据类名示例化类即时类getEpochSecond()方法 (Instant Class getEpochSecond() method) getEpochSecond() method is available in java.time package. getEpochSecond()方法在java.time包中可用。 getEpochSecond() method is used to get the number of seconds from t…

oracle10g备份导入

2019独角兽企业重金招聘Python工程师标准>>> //导出 exp test/testgdsoft filed:\gd.dmp //删用户 drop user wkwx cascade; //用PLSQL创建数据数据库 create user hzjzjn identified by hzjzjn default tablespace BDP_DATABD; grant CREATE USER,DROP USER,ALTE…

VisualSVNServer的使用

VisualSVNServer的使用1_服务端初识1.1_创建新仓库1.2_创建用户并分配权限1_服务端初识 1.1_创建新仓库 右击Repository,点击create 点击下一步 输入仓库名 右击空白处,点击新建,点击project structure 输入工程名 1.2_创建用户并分…

安利一个IDEA骚操作:一键生成方法的序列图

在平时的学习/工作中,我们会经常面临如下场景:阅读别人的代码阅读框架源码阅读自己很久之前写的代码。千万不要觉得工作就是单纯写代码,实际工作中,你会发现你的大部分时间实际都花在了阅读和理解已有代码上。为了能够更快更清晰地…

overflow滚动条属性

做网页的时候,因为网页内容的长短不一样,并且滚动条的策略默认是自动,所以网页的滚动条根据内容一会有一会没有。我的网页做的是居中的,所以滚动条在有和没有的时候,会影响网页内容的位置,这样感觉不太好&a…

c#中textbox属性_C#.Net中带有示例的TextBox.Multiline属性

c#中textbox属性Here we are demonstrating use of Multiline property of the TextBox Control. 在这里,我们演示了TextBox控件的Multiline属性的使用。 Multiline property contains two values: 多行属性包含两个值: True: We can enter text in mo…

MATLAB新手教程

MATLAB新手教程 1.MATLAB的基本知识 1-1、基本运算与函数 在MATLAB下进行基本数学运算,仅仅需将运算式直接打入提示号(>>)之後,并按入Enter键就可以。比如: >> (5*21.3-0.8)*10/25 an…

嗯,查询滑动窗口最大值的这4种方法不错....

作者 | 王磊来源 | Java中文社群(ID:javacn666)转载请联系授权(微信ID:GG_Stone)本文已收录至 Github《小白学算法》系列:https://github.com/vipstone/algorithm这是一道比较基础的算法题&…

Oracle创建视图、通过视图创建表

创建视图: create or replace view v$_tst23 as select e.ename,d.dname from emp e left join dept d on e.deptno d.deptno;创建表: --如果表已存在,先删除 --drop table tst23a; --创建表格(通过视图) --可以在whe…

SVN客户端使用

SVN客户端使用1. 复制服务端URL2. 在客户端电脑新建文件夹用于存储版本代码3. 右击空白处,checkout4. 进入trunk目录,即可尝试新建文件并上传到服务端4.其他客户端更新版本5.解决代码冲突期间由于之前登陆过并设置为记住密码,所以整个过程并没…

c ++ stl_获取列表的第一个和最后一个元素| C ++ STL

c stlGiven a list with some of the elements, we have to access its first and last elements of the list in C (STL) program. 给定包含某些元素的列表,我们必须在C (STL)程序中访问列表的第一个和最后一个元素。 列表的front()和back()函数 (front() and ba…

细说新一代HTML5/JavaScript的UI控件wijmo5 的新架构

Wijmo 5是一组JavaScript控件,但是不要与Widgets混淆。在此前开发Wijmo的时候,我们能够用像jQuery UI和jQuery Mobile Widget 框架来构建它,同时也为我们构建Web框架--Wijmo节省了时间。但是,当我们希望构建一个更现代的Wijmo 5&a…

SSH:hql语句传参报错,及antlr-2.7.2.jar重复包的删除

问题: 使用hql语句时出现 java.lang.reflect.InvocationTargetException(即使用hql回调函数带参数时) 或者是 antlr.collections.AST.getLine()I异常 【解决方法一:myeclipse8.6/10】 我用的myeclipse8.6,(10也是同样的方法&…

25 张图,1.4 w字!彻底搞懂分布式事务原理

本文提纲如下:0. 前言1. 单数据源事务 & 多数据源事务2. 常见分布式事务解决方案2.1. 分布式事务模型2.2. 二将军问题和幂等性2.3. 两阶段提交(2PC) & 三阶段提交(3PC)方案2.4. TCC 方案2.5. 事务状态表方案2.…

tableau使用事项

解决加载地图失败问题 如何使用mapbox