java把13位时间戳转换成"yyyy-MM-dd HH:mm:ss"格式,工具类

 

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/zyf-yxm/p/9014309.html