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 convers unix time stamp to Date.
public static Date getDate(long unixTimestamp) {
return new Date(unixTimestamp * 1000);
}
App.java
package com.sample.app;
import java.util.Date;
public class App {
public static Date getDate(long unixTimestamp) {
return new Date(unixTimestamp * 1000);
}
public static void main(String[] args) {
Date date = getDate(1577603360);
System.out.println(date);
}
}
Output
Sun Dec 29 12:39:20 IST 2019
You may
like
No comments:
Post a Comment