Consider the output from the code below with and without the call to get Calendar.HOUR_OF_DAY:
XMLGregorianCalendar cal = datatypeFactory.newXMLGregorianCalendar("1994-08-10T00:00:00Z");
System.out.println("Cal: " + cal);
GregorianCalendar gCal = cal.toGregorianCalendar();
gCal.get(Calendar.HOUR_OF_DAY); // this line makes a difference
gCal.setTimeZone(TimeZone.getTimeZone("GMT-07"));
XMLGregorianCalendar newCal = datatypeFactory.newXMLGregorianCalendar(gCal.get(Calendar.YEAR),
gCal.get(Calendar.MONTH)+1, gCal.get(Calendar.DAY_OF_MONTH),
gCal.get(Calendar.HOUR_OF_DAY),
gCal.get(Calendar.MINUTE), gCal.get(Calendar.SECOND),
gCal.get(Calendar.MILLISECOND),
(gCal.get(Calendar.ZONE_OFFSET) + gCal.get(Calendar.DST_OFFSET))/60000);
System.out.println("New Cal: " + newCal);
With call to get(Calendar.HOUR_OF_DAY), the output is:
Cal: 1994-08-10T00:00:00Z
New Cal: 1994-08-09T17:00:00.000-07:00
Without the call to get(Calendar.HOUR_OF_DAY), the output is:
Cal: 1994-08-10T00:00:00Z
New Cal: 1994-08-10T00:00:00.000-07:00
Looks like the the get() call on GregorianCalendar kicks off some kind of field compute resolutions? Seems odd that this would be the case. Am I missing something?