代码:
public static void main(String[] args) {
Long milliSecond = System.currentTimeMillis();
System.out.println(milliSecond);
Map<String,Object> formMap = new HashMap<>();
formMap.put("htkssj",milliSecond);
String htkssj = formMap.get("htkssj")!=null?formMap.get("htkssj").toString():"";
String date = timeMillilsTransDateString(htkssj);
System.out.println(date);
}
public static String timeMillilsTransDateString(String timeMilles){
Long time = timeMilles!="" ? Long.parseLong(timeMilles) : null;
if(time!=null){
Date date = new Date();
date.setTime(time);
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
}
return "";
}
由于项目中是通过从Map中获取到的时间戳,转换成时间,代码中模拟了根据字符串转换时间,简单些可以直接通过Long类型转换成Date