diff --git a/src/main/java/com/alibaba/fastjson/parser/deserializer/Jdk8DateCodec.java b/src/main/java/com/alibaba/fastjson/parser/deserializer/Jdk8DateCodec.java index c797de1a21..a708897e9a 100644 --- a/src/main/java/com/alibaba/fastjson/parser/deserializer/Jdk8DateCodec.java +++ b/src/main/java/com/alibaba/fastjson/parser/deserializer/Jdk8DateCodec.java @@ -520,6 +520,8 @@ public void write(JSONSerializer serializer, Object object, Object fieldName, Ty if (format == null) { if ((features & mask) != 0 || serializer.isEnabled(SerializerFeature.UseISO8601DateFormat)) { format = formatter_iso8601_pattern; + } else if (serializer.isEnabled(SerializerFeature.WriteDateUseDateFormat)) { + format = JSON.DEFFAULT_DATE_FORMAT; } else { int nano = dateTime.getNano(); if (nano == 0) { @@ -534,9 +536,6 @@ public void write(JSONSerializer serializer, Object object, Object fieldName, Ty if (format != null) { write(out, dateTime, format); - } else if (out.isEnabled(SerializerFeature.WriteDateUseDateFormat)) { - //使用固定格式转化时间 - write(out, dateTime, JSON.DEFFAULT_DATE_FORMAT); } else { out.writeLong(dateTime.atZone(JSON.defaultTimeZone.toZoneId()).toInstant().toEpochMilli()); }