ChronoLocalDate toEpochDay() method in Java with Examples
The toEpochDay() method of a ChronoLocalDate interface is used to get this date as a EpochDay. The EpochDay is the count of the day from the 0 EpochDay which is the 1970-01-01 (ISO). The output will be in the ISO-8601 format yyyy-MM-dd.
Syntax:
default long toEpochDay()
Parameters: This method does not accepts any parameters.
Return value: This method returns a long value which is the EpochDay count of this date, not null.
Below programs illustrate the toEpochDay() method:
Program 1:
// Java program to demonstrate // ChronoLocalDate.toEpochDay() method import java.time.*; import java.time.chrono.*; public class GFG { public static void main(String[] args) { // create a ChronoLocalDate object ChronoLocalDate localD = LocalDate.parse("2018-12-06"); // print ChronoLocalDate System.out.println("ChronoLocalDate as EpochDay: " + localD.toEpochDay()); } } |
ChronoLocalDate as EpochDay: 17871
Program 2:
// Java program to demonstrate // ChronoLocalDate.toEpochDay() method import java.time.*; import java.time.chrono.*; public class GFG { public static void main(String[] args) { // create a ChronoLocalDate object ChronoLocalDate localD = LocalDate.parse("2021-06-30"); // print ChronoLocalDate System.out.println("ChronoLocalDate as EpochDay: " + localD.toEpochDay()); } } |
ChronoLocalDate as EpochDay: 18808
Reference: https://docs.oracle.com/javase/9/docs/api/java/time/chrono/ChronoLocalDate.html#toEpochDay–
Recommended Posts:
- ChronoLocalDate until(ChronoLocalDate) Method in Java with Examples
- ChronoLocalDate from() method in Java with Examples
- ChronoLocalDate get() method in Java with Examples
- ChronoLocalDate isLeapYear() method in Java with Examples
- ChronoLocalDate hashCode() method in Java with Examples
- ChronoLocalDate plus(TemporalAmount) method in Java with Examples
- ChronoLocalDate isBefore() method in Java with Examples
- ChronoLocalDate range() method in Java with Examples
- ChronoLocalDate isAfter() method in Java with Examples
- LocalDate until(ChronoLocalDate) Method in Java with Examples
- ChronoLocalDate lengthOfMonth() method in Java with Examples
- ChronoLocalDate adjustInto() method in Java with Examples
- ChronoLocalDate query() Method in Java with Examples
- ChronoLocalDate compareTo() method in Java with Examples
- ChronoLocalDate lengthOfYear() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



