Convert this XMLGregorianCalendar
to a {@link GregorianCalendar}.
When this
instance has an undefined field, this conversion relies on the java.util.GregorianCalendar
default for its corresponding field. A notable difference between XML Schema 1.0 date/time datatypes and java.util.GregorianCalendar
is that Timezone value is optional for date/time datatypes and it is a required field for java.util.GregorianCalendar
. See javadoc for java.util.TimeZone.getDefault()
on how the default is determined. To explicitly specify the TimeZone
instance, see {@link #toGregorianCalendar(TimeZone,Locale,XMLGregorianCalendar)}.
Field by Field Conversion from this class to java.util.GregorianCalendar |
java.util.GregorianCalendar field | javax.xml.datatype.XMLGregorianCalendar field |
ERA | {@link #getEonAndYear()}.signum() < 0 ? GregorianCalendar.BC : GregorianCalendar.AD |
YEAR | {@link #getEonAndYear()}.abs().intValue() * |
MONTH | {@link #getMonth()} - {@link DatatypeConstants#JANUARY} + {@link GregorianCalendar#JANUARY} |
DAY_OF_MONTH | {@link #getDay()} |
HOUR_OF_DAY | {@link #getHour()} |
MINUTE | {@link #getMinute()} |
SECOND | {@link #getSecond()} |
MILLISECOND | get millisecond order from {@link #getFractionalSecond()}* |
GregorianCalendar.setTimeZone(TimeZone) | {@link #getTimezone()} formatted into Custom timezone id |
* designates possible loss of precision during the conversion due to source datatype having higher precision than target datatype.
To ensure consistency in conversion implementations, the new GregorianCalendar
should be instantiated in following manner.
- Using
timeZone
value as defined above, create a new java.util.GregorianCalendar(timeZone,Locale.getDefault())
. - Initialize all GregorianCalendar fields by calling {(@link GegorianCalendar#clear()}.
- Obtain a pure Gregorian Calendar by invoking
GregorianCalendar.setGregorianChange( new Date(Long.MIN_VALUE))
. - Its fields ERA, YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY, MINUTE, SECOND and MILLISECOND are set using the method
Calendar.set(int,int)
@see #toGregorianCalendar(java.util.TimeZone,java.util.Locale,XMLGregorianCalendar)