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

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

LocalDate类的YearDay()方法 (LocalDate Class ofYearDay() method)

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

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

  • ofYearDay() method is used to create an instance of LocalDate object that holds the value from the year and day-of-year.

    ofYearDay()方法用于创建LocalDate对象的实例,该实例保存年份和年份中的值。

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

    ofYearDay()方法是一个静态方法,可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会收到错误。

  • ofYearDay() method may throw an exception at the time of representing the day of the year.

    ofYearDay()方法在表示一年中的某天时可能会引发异常。

    DateTimeException: This exception may throw when the calculated result value exceeds the limit.

    DateTimeException :当计算结果值超出限制时,可能引发此异常。

Syntax:

句法:

public LocalDate ofYearDay(int yyyy, int ddOfyyyy);

Parameter(s):

参数:

  • int yyyy – represents the year and starts from MIN_YEAR to MAX_YEAR.

    int yyyy –表示年份,从MIN_YEAR到MAX_YEAR。

  • int ddOfyyyy – represents the days in a year and the number of days in a year from 1 to 365 (for non-leap) 366 (for leap year).

    int ddOfyyyy –表示一年中的天数和一年中的天数,范围是1到365(对于非le年)是366(对于leap年)。

Return value:

返回值:

The return type of this method is LocalDate, it returns the LocalDate that holds the value represented from a year and day-of-year.

此方法的返回类型为LocalDate ,它返回LocalDate,该LocalDate包含从年份和年份中表示的值。

Example:

例:

// Java program to demonstrate the example // of ofYearDay(int yyyy, int ddOfyyyy)// method of LocalDateimport java.time.*;public class OfYearDayOfLocalDate {
public static void main(String args[]) {
int year = 2008; int day_of_year = 50; // Here, this method creates an instance // of LocalDate by using the given year // and day_of_year i.e. 2008-02-19 // [year = 2008, day_of_year = 50 // (Jan = 31 days + Feb = 19 days ) // {2008, Feb, 19} so 2008-02-19] LocalDate of_year_day = LocalDate.ofYearDay(year, day_of_year); // Display of_year_day System.out.println("LocalDate.ofYearDay(year,day_of_year): " + of_year_day); }}

Output

输出量

LocalDate.ofYearDay(year,day_of_year): 2008-02-19

翻译自:

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

你可能感兴趣的文章
Number Triangles
查看>>
Ext分页实现(前台与后台)
查看>>
转 迭代器模式
查看>>
CYQ.Data V5 MAction新增加SetExpression方法说明
查看>>
数据安全&MD5加密
查看>>
bzoj 2594: 水管局长数据加强版 Link-Cut-Tree
查看>>
世界是数字的观后感
查看>>
由DBCursor的“can't switch cursor access methods”异常引发的思考
查看>>
LUOGU P1438 无聊的数列 (差分+线段树)
查看>>
引用和指针的区别
查看>>
stm32 usart 异步传输示例
查看>>
yum 安装过程下载的包存放路径
查看>>
二叉树
查看>>
idea下http响应乱码
查看>>
jquery使用$.each()
查看>>
Sybase 15.7 开发版下载(非注册)
查看>>
P1527 [国家集训队]矩阵乘法
查看>>
java 包(package)
查看>>
android Service介绍
查看>>
[MySQL 5.6] GTID实现、运维变化及存在的bug
查看>>