ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Java LocalDate Class | ofEpochDay() Method with Example

LocalDate Class ofEpochDay() method: Here, we are going to learn about the ofEpochDay() method of LocalDate Class with its syntax and example.
Submitted by Preeti Jain, on May 31, 2020

LocalDate Class ofEpochDay() method

  • ofEpochDay() method is available in java.time package.
  • ofEpochDay() method is used to create an instance of LocalDate to count the given days from the epoch of 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() method may throw an exception at the time of representing days.
    DateTimeException: This exception may throw when the calculated result value exceeds the limit.

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).

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.

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
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.