Java Data Type How to - Create Instant from Milliseconds from Epoch








Question

We would like to know how to create Instant from Milliseconds from Epoch.

Answer

import java.time.Instant;
/* w w w .j  a v  a2  s .  com*/
public class Main {
  public static void main(String[] args) {

    // same time in millis
    Instant fromEpochMilli = Instant.ofEpochMilli(1262347200000l);
    
    System.out.println(fromEpochMilli);
  }
}

The code above generates the following result.