JAVA - Unix time stamp to time
Unix 时间戳转换:
/*
* Unix time stamp to time
*/
public static String TimeStamp2Date(String timestampString){
Long timestamp = Long.parseLong(timestampString)*1000;
String date = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date(timestamp));
return date;
}
一般的时间戳转换:
/*
* time stamp to time
*/
public static String stampToDate(String s){
String res;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long lt = new Long(s);
Date date = new Date(lt);
res = simpleDateFormat.format(date);
return res;
}
输出:
public static void main(String[] args) throws UnknownHostException {
System.out.println("time : "+stampToDate("1541645357"));
System.out.println("Unix : "+TimeStamp2Date("1541645357"));
}
outprint:
time : 1970-01-19 04:14:05
Unix : 2018-11-08 10:49:17