Java Data Type How to - Get date time from the base date i.e 01/01/1970








Question

We would like to know how to get date time from the base date i.e 01/01/1970.

Answer

/*  w ww.j  a  va  2s.  co  m*/
import java.time.LocalDateTime;
import java.time.ZoneOffset;

public class Main {
    public static void main(String[] args) {
      //Getting date from the base date i.e 01/01/1970
      LocalDateTime dateFromBase = LocalDateTime.ofEpochSecond(10000, 0, ZoneOffset.UTC);
      System.out.println("10000th second time from 01/01/1970= "+dateFromBase);
    }
}

The code above generates the following result.