-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Closed
Labels
Description
As described in https://stackoverflow.com/questions/6873020/gson-date-format, calling Gson.setDateFormat(int) has no effect, the created Gson object will not use the date format.
It appears the reason for this is that the method only sets dateStyle, but timeStyle remains unchanged, i.e. if it has not been changed before, then it is still DateFormat.DEFAULT.
gson/gson/src/main/java/com/google/gson/GsonBuilder.java
Lines 451 to 454 in 63ee47c
| public GsonBuilder setDateFormat(int style) { | |
| this.dateStyle = style; | |
| this.datePattern = null; | |
| return this; |
However addTypeAdaptersForDate only uses the styles if timeStyle != DateFormat.DEFAULT.
| } else if (dateStyle != DateFormat.DEFAULT && timeStyle != DateFormat.DEFAULT) { |