private static String[] parsePatterns = {
"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
"yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM","yyyy-MM-dd HH:mm:ss.SSS"};
//使用方法
public static String formatDate(Date date, Object... pattern) {
String formatDate = null;
if (pattern != null && pattern.length > 0) {
formatDate = DateFormatUtils.format(date, pattern[0].toString());
} else {
formatDate = DateFormatUtils.format(date, "yyyy-MM-dd");
}
return formatDate;
}
//实际用法
private Long id;
private Date lastModifyTime;
private String lastModifyTimeStr;
private String key;
private String value;
private Integer is_Del;
public String getLastModifyTimeStr() {
if(lastModifyTime != null) {
return DateUtils.formatDate(lastModifyTime, "yyyy-MM-dd HH:mm:ss");
}
return lastModifyTimeStr;
}
展示效果如下
result: [
{
id: 21,
lastModifyTime: “2019-05-31T06:10:28.000+0000”,
lastModifyTimeStr: “2019-05-31 14:10:28”,
key: “APP_NAME”,
value: “巨龙数据平台”,
is_Del: 1,
orgCode: null,
appCode: null
}
总结:
将数据库中保存的日期 如 “2019-05-31T06:10:28.000+0000”
转换成 前端展示的 “2019-05-31 14:10:28”
在封装类中添加字段 private Date lastModifyTime;
private String lastModifyTimeStr;
再做转换