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