Monday, November 18, 2024
Google search engine
HomeLanguagesJavaChronoLocalDate toEpochDay() method in Java with Examples

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());
    }
}


Output:

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());
    }
}


Output:

ChronoLocalDate as EpochDay: 18808

Reference: https://docs.oracle.com/javase/9/docs/api/java/time/chrono/ChronoLocalDate.html#toEpochDay–

RELATED ARTICLES

Most Popular

Recent Comments