Java LocalDate类| ofEpochDay()方法与示例

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值