Sunday, 8 March 2020

Get Instant from Unix time stamp

Unix time is the number of seconds that have elapsed since 00:00:00, 1 January 1970, UTC, without counting the leap seconds.

You can get Unix time stamp by executing the command date '+%s' on terminal.

$date '+%s'
1577603360

Below snippet converts unix time stamp to Instant.

long unixTimestamp = 1577603360;
Instant instant = Instant.ofEpochSecond(unixTimestamp);

App.java
package com.sample.app;

import java.time.Instant;

public class App {

 public static void main(String[] args) {
  long unixTimestamp = 1577603360;

  Instant instant = Instant.ofEpochSecond(unixTimestamp);

  System.out.println(instant);
 }

}

Output
2019-12-29T07:09:20Z

You may like
Previous                                                    Next                                                    Home

No comments:

Post a Comment