EpochDay()方法的LocalDate类 (LocalDate Class ofEpochDay() method)
ofEpochDay() method is available in java.time package.
ofEpochDay()方法在java.time包中可用。
ofEpochDay() method is used to create an instance of LocalDate to count the given days from the epoch of 1970-01-01.
ofEpochDay()方法用于创建LocalDate的实例,以计算从1970-01-01时代开始的给定天数。
ofEpochDay() 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.
ofEpochDay()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
ofEpochDay() method may throw an exception at the time of representing days.
ofEpochDay()方法在表示天数时可能会引发异常。
DateTimeException: This exception may throw when the calculated result value exceeds the limit.
DateTimeException :当计算结果值超出限制时,可能引发此异常。
Syntax:
句法:
public LocalDate ofEpochDay(long days_val);
Parameter(s):
参数:
long days_val – represents the day to change into epoch day with the help of epoch format 1970-01-01 (since 1 Jan 1970).
long days_val –代表通过纪元格式1970-01-01(从1970年1月1日开始)更改为纪元日的日期。
Return value:
返回值:
The return type of this method is LocalDate, it returns the LocalDate that holds the day value converted the given days based on 1970-01-01.
此方法的返回类型为LocalDate ,它返回LocalDate,该LocalDate包含根据1970-01-01将给定日期转换为日期的日期值。
Example:
例:
// Java program to demonstrate the example
// of ofEpochDay(long days_val) method of LocalDate
import java.time.*;
public class OfEpochDayOfLocalDate {
public static void main(String args[]) {
long ep_day = 60;
// Here, this method creates an instance
// of LocalDate by using the given epoch
// day count from 1970-01-01 i.e.
// (1970-01-01 + 60 days = 1970-03-02)
LocalDate epoch_day = LocalDate.ofEpochDay(60);
// Display epoch_day
System.out.println("LocalDate.ofEpochDay(60): " + epoch_day);
// Here, this method creates an instance
// of LocalDate by using the given epoch
// day count from 1970-01-01 i.e.
// (1970-01-01 + 50 days = 1970-02-20)
epoch_day = LocalDate.ofEpochDay(50);
// Display epoch_day
System.out.println("LocalDate.ofEpochDay(50): " + epoch_day);
}
}
Output
输出量
LocalDate.ofEpochDay(60): 1970-03-02
LocalDate.ofEpochDay(50): 1970-02-20
翻译自: https://www.includehelp.com/java/localdate-ofepochday-method-with-example.aspx