|
|
@@ -18,15 +18,21 @@ import java.util.TimeZone;
|
|
|
public class CustomDateSerializer extends StdSerializer<Date> {
|
|
|
|
|
|
private static String defaultTimeZone;
|
|
|
+ private static String defaultTimeFormat;
|
|
|
|
|
|
public CustomDateSerializer(String timeZone) {
|
|
|
+ this("yyyy-MM-dd HH:mm:ss", timeZone);
|
|
|
+ }
|
|
|
+
|
|
|
+ public CustomDateSerializer(String timeFormat, String timeZone) {
|
|
|
super(Date.class);
|
|
|
+ defaultTimeFormat = timeFormat;
|
|
|
defaultTimeZone = timeZone;
|
|
|
}
|
|
|
|
|
|
// 线程安全的SimpleDateFormat(避免多线程问题)
|
|
|
private static final ThreadLocal<SimpleDateFormat> SDF_THREAD_LOCAL = ThreadLocal.withInitial(() -> {
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat(defaultTimeFormat);
|
|
|
sdf.setTimeZone(TimeZone.getTimeZone(defaultTimeZone));
|
|
|
return sdf;
|
|
|
});
|