Java Program to create Instant from Epoch second and millisecond


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

Updated on: 30-Jul-2019

981 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements