--------------------------------------原先逻辑------------------------------------------------------
if (object instanceof Date) {
if ("unixtime".equals(format)) {
long seconds = ((Date) object).getTime() / 1000L;
out.writeInt((int) seconds);
return;
}
DateFormat dateFormat = this.getDateFormat();
if (dateFormat == null) {
try {
dateFormat = new SimpleDateFormat(format, locale);
} catch (IllegalArgumentException e) {
String format2 = format.replaceAll("T", "'T'");
dateFormat = new SimpleDateFormat(format2, locale);
}
dateFormat.setTimeZone(timeZone);
}
String text = dateFormat.format((Date) object);
out.writeString(text);
return;
}
--------------------------时间格式化优先顺序调整------------------------------------------
if (object instanceof Date) {
if ("unixtime".equals(format)) {
long seconds = ((Date) object).getTime() / 1000L;
out.writeInt((int) seconds);
return;
}
DateFormat dateFormat = null;
//时间格式化先后顺序调整:
// 当在某一具体时间类型的字段注解format时间格式化时,已注解为主,全局配置为辅
//是为了在FastJsonHttpMessageConverter处理时返回时间类型字段时,只处理未在vo注解的时间类型字段
if(format != null){
try {
dateFormat = new SimpleDateFormat(format, locale);
} catch (IllegalArgumentException e) {
String format2 = format.replaceAll("T", "'T'");
dateFormat = new SimpleDateFormat(format2, locale);
}
dateFormat.setTimeZone(timeZone);
}else{
dateFormat = this.getDateFormat();
}
String text = dateFormat.format((Date) object);
out.writeString(text);
return;
}
暂无答案!
目前还没有任何答案,快来回答吧!