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 LocalDate
import 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
翻译自: https://www.includehelp.com/java/localdate-ofyearday-method-with-example.aspx