To print the date (not date time) value of java.sql.Date, the XMLConverterFactory changes the timezone to GMT, which might shift the date by +/-1, depending on the systems timezone and results in a wrong value.
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
cal.setTimeInMillis(((java.util.Date) unconvertedValue).getTime());
DatatypeConverterImpl converter = DatatypeConverterImpl.getInstance();
if (unconvertedValue instanceof java.sql.Date) {
textValue = converter.printDate(cal);
} else if (unconvertedValue instanceof java.sql.Time) {
textValue = converter.printTime(cal);
} else {
textValue = converter.printDateTime(cal);
}
If a conversion of java.sql.Date to string is requested it is very likely that the date shall remain stable. Otherwise a java.util.Date should be used. The XMLConverterFactory should take the timezone offset into account, when changing the timezone. The same issue was fixed in GeoServer recently: GEOS-6777 In addition to the XMLConverterFactory the XSDateBinding is affected. |