Java Convert LocalDate to Epoch Day

Tags: Java LocalDate Java 8

Epoch Day is the incrementing count of days where day 0 is 1970-01-01. In this Java core tutorial we learn how to convert a java.time.LocalDate object to Epoch Day in Java programming language.

How to convert LocalDate to Epoch Day in Java

With a given LocalDate object in Java we can use the LocalDate.toEpochDay() method to get value of Epoch Day as the following Java program.

ConvertLocalDateToEpochDaysExample1.java

import java.time.LocalDate;

public class ConvertLocalDateToEpochDaysExample1 {
    public static void main(String... args) {
        LocalDate localDate = LocalDate.of(2022, 7, 11);
        long epochDay = localDate.toEpochDay();

        System.out.println("LocalDate: " + localDate);
        System.out.println("Epoch Day: " + epochDay);
    }
}
The output as below.
LocalDate: 2022-07-11
Epoch Day: 19184

Happy Coding 😊

Java LocalDate by Examples

Java Convert LocalDate to String

Java Convert LocalDate to LocalDateTime

Java Convert LocalDate to OffsetDateTime

Java Convert LocalDate to ZonedDateTime

Java Convert LocalDate to Date

Java Convert LocalDate to Calendar

Java Convert Date to LocalDate

Java Convert Calendar to LocalDate

Java Convert Epoch Day to LocalDate