Syntax error Java Program to get Milli seconds from Instant

Java Program to get Milli seconds from Instant



Create an Instant and get an Instant using milliseconds passed as parameter from the epoch of 1970-01- 01T00:00:00Z. This is done using ofEpochMilli():

Instant instant = Instant.ofEpochMilli(342627282920l);

Now, get the Epoch milliseconds from Instant:

instant. toEpochMilli();

Example

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

Output

1262347200000
Updated on: 2019-07-30T22:30:25+05:30

245 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements