Java LocalDate get days from Epoch

Introduction

Convert the date to epoch days.

The epoch days is the number of days from 1970-01-01 to a date.

A date before 1970-01-01 returns a negative integer.

import java.time.LocalDate;

public class Main {
  public static void main(String[] args) {
    LocalDate ld = LocalDate.of(2020, 5, 2); // 2020-05-02

    long epochDays = ld.toEpochDay();

    System.out.println(epochDays);
  }/*from www  . j  a  v  a2 s  .  c o  m*/
}



PreviousNext

Related