Java Program to create Instant from Epoch second and millisecond

Java 8Object Oriented ProgrammingProgramming

Create Instant from Epoch Second

Example

import java.time.Instant;
public class Demo {
   public static void main(String[] args) {
      Instant instant = Instant.ofEpochSecond(282829279);
      System.out.println(instant);
   }
}

Output

1978-12-18T11:41:19Z

Create Instant from Epoch Milliseconds

Example

import java.time.Instant;
public class Demo {
   public static void main(String[] args) {
      Instant instant = Instant.ofEpochMilli(272827282728l);
      System.out.println(instant);
   }
}

Output

1978-08-24T17:21:22.728Z
raja
Published on 24-Apr-2019 11:49:36
Advertisements