java 时间戳转换为日期格式
时间:2021-09-06 20:06:24
收藏:0
阅读:16
public static void main(String[] args) {
String time = System.currentTimeMillis();//获取当前时间精确到毫秒级的时间戳,例:1525849325942
System.out.println(timeStamp2Date(time))
}
public static String timeStamp2Date(String time) {
Long timeLong = Long.parseLong(time);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//要转换的时间格式
Date date;
try {
date = sdf.parse(sdf.format(timeLong));
return sdf.format(date);
} catch (ParseException e) {
e.printStackTrace();
return null;
}
}
原文:https://www.cnblogs.com/alvisClub/p/15233124.html
评论(0)