APIdia Launch Partner
Top Description Constructors Methods
javax.xml.datatype

public abstract Class XMLGregorianCalendar

extends Object
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Known Direct Subclasses
com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl
Imports
javax.xml.namespace.QName, java.math.BigDecimal, .BigInteger, java.util.Arrays, .TimeZone, .GregorianCalendar

Representation for W3C XML Schema 1.0 date/time datatypes. Specifically, these date/time datatypes are DatatypeConstants#DATETIME, DatatypeConstants#TIME, DatatypeConstants#DATE, DatatypeConstants#GYEARMONTH, DatatypeConstants#GMONTHDAY, DatatypeConstants#GYEAR, DatatypeConstants#GMONTH, and DatatypeConstants#GDAY defined in the XML Namespace "http://www.w3.org/2001/XMLSchema". These datatypes are normatively defined in W3C XML Schema 1.0 Part 2, Section 3.2.7-14.

The table below defines the mapping between XML Schema 1.0 date/time datatype fields and this class' fields. It also summarizes the value constraints for the date and time fields defined in W3C XML Schema 1.0 Part 2, Appendix D, ISO 8601 Date and Time Formats.

Date/Time Datatype Field Mapping Between XML Schema 1.0 and Java Representation
XML Schema 1.0
datatype
field
Related
XMLGregorianCalendar
Accessor(s)
Value Range
year getYear() + getEon() or
getEonAndYear
getYear() is a value between -(10^9-1) to (10^9)-1 or DatatypeConstants#FIELD_UNDEFINED.
getEon() is high order year value in billion of years.
getEon() has values greater than or equal to (10^9) or less than or equal to -(10^9). A value of null indicates field is undefined.
Given that XML Schema 1.0 errata states that the year zero will be a valid lexical value in a future version of XML Schema, this class allows the year field to be set to zero. Otherwise, the year field value is handled exactly as described in the errata and [ISO-8601-1988]. Note that W3C XML Schema 1.0 validation does not allow for the year field to have a value of zero.
month getMonth() 1 to 12 or DatatypeConstants#FIELD_UNDEFINED
day getDay() Independent of month, max range is 1 to 31 or DatatypeConstants#FIELD_UNDEFINED.
The normative value constraint stated relative to month field's value is in W3C XML Schema 1.0 Part 2, Appendix D.
hour getHour() 0 to 23 or DatatypeConstants#FIELD_UNDEFINED. An hour value of 24 is allowed to be set in the lexical space provided the minute and second field values are zero. However, an hour value of 24 is not allowed in value space and will be transformed to represent the value of the first instance of the following day as per XML Schema Part 2: Datatypes Second Edition, 3.2 Primitive datatypes.
minute getMinute() 0 to 59 or DatatypeConstants#FIELD_UNDEFINED
second getSecond() + getMillisecond()/1000 or
getSecond() + getFractionalSecond()
getSecond() from 0 to 60 or DatatypeConstants#FIELD_UNDEFINED.
(Note: 60 only allowable for leap second.)
getFractionalSecond() allows for infinite precision over the range from 0.0 to 1.0 when the getSecond() is defined.
FractionalSecond is optional and has a value of null when it is undefined.
getMillisecond() is the convenience millisecond precision of value of getFractionalSecond().
timezone getTimezone() Number of minutes or DatatypeConstants#FIELD_UNDEFINED. Value range from -14 hours (-14 * 60 minutes) to 14 hours (14 * 60 minutes).

All maximum value space constraints listed for the fields in the table above are checked by factory methods, DatatypeFactory, setter methods and parse methods of this class. IllegalArgumentException is thrown when a parameter's value is outside the value constraint for the field or if the composite values constitute an invalid XMLGregorianCalendar instance (for example, if the 31st of June is specified).

The following operations are defined for this class:

Authors
Joseph Fialli, Kohsuke Kawaguchi, Jeff Suttor, Sunitha Reddy
Since
1.5
See Also
Duration, DatatypeFactory

Constructor Summary

AccessConstructor and Description
public
XMLGregorianCalendar()

Default no-arg constructor.

Method Summary

Modifier and TypeMethod and Description
public abstract void
add(Duration
Duration to add to this XMLGregorianCalendar.
duration
)

Add duration to this instance.

public abstract void
clear()

Unset all fields to undefined.

public abstract Object

Returns:

copy of this Object
clone
()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.

public abstract int

Returns:

The relationship between this XMLGregorianCalendar and the specified xmlGregorianCalendar as DatatypeConstants#LESSER, DatatypeConstants#EQUAL, DatatypeConstants#GREATER or DatatypeConstants#INDETERMINATE.
compare
(XMLGregorianCalendar
Instance of XMLGregorianCalendar to compare
xmlGregorianCalendar
)

Compare two instances of W3C XML Schema 1.0 date/time datatypes according to partial order relation defined in W3C XML Schema 1.0 Part 2, Section 3.2.7.3, Order relation on dateTime.

public boolean

Returns:

true when obj is an instance of XMLGregorianCalendar and compare(XMLGregorianCalendar obj) returns DatatypeConstants#EQUAL, otherwise false.
equals
(Object
to compare.
obj
)

Overrides java.lang.Object.equals.

Compares this calendar to the specified object.

public abstract int

Returns:

The day of month of this XMLGregorianCalendar, from 1 to 31.
getDay
()

Returns the day of month or DatatypeConstants#FIELD_UNDEFINED.

public abstract BigInteger

Returns:

The eon of this XMLGregorianCalendar. The value returned is an integer multiple of 10^9.
getEon
()

Returns the high order component for XML Schema 1.0 dateTime datatype field for year.

public abstract BigInteger

Returns:

sum of eon and BigInteger.valueOf(year) when both fields are defined. When only year is defined, return it. When both eon and year are not defined, return null.
getEonAndYear
()

Returns the XML Schema 1.0 dateTime datatype field for year.

public abstract BigDecimal

Returns:

Fractional seconds of this XMLGregorianCalendar.
getFractionalSecond
()

Returns fractional seconds.

public abstract int

Returns:

The hour of day of this XMLGregorianCalendar, from 0 to 23.
getHour
()

Returns the hour of day or DatatypeConstants#FIELD_UNDEFINED if this field is not defined.

public int

Returns:

The millisecond precision of this XMLGregorianCalendar.
getMillisecond
()

Returns the millisecond precision of getFractionalSecond().

public abstract int

Returns:

The minute of hour of this XMLGregorianCalendar, from 0 to 59.
getMinute
()

Returns the minute of hour or DatatypeConstants#FIELD_UNDEFINED if this field is not defined.

public abstract int

Returns:

The month of this XMLGregorianCalendar, from 1 to 12.
getMonth
()

Returns the month of this calendar or DatatypeConstants#FIELD_UNDEFINED.

public abstract int

Returns:

The second of minute of this XMLGregorianCalendar, from 0 to 59.
getSecond
()

Returns the second of minute or DatatypeConstants#FIELD_UNDEFINED if this field is not defined.

public abstract int

Returns:

The Timezone offset in minutes of this XMLGregorianCalendar.
getTimezone
()

Returns the Timezone offset in minutes or DatatypeConstants#FIELD_UNDEFINED if this optional field is not defined.

public abstract TimeZone

Returns:

TimeZone for this.
getTimeZone
(int
default zoneoffset if this zoneoffset is DatatypeConstants#FIELD_UNDEFINED.
defaultZoneoffset
)

Returns a java.util.TimeZone for this class.

public abstract QName
getXMLSchemaType()

Return the name of the XML Schema date/time type that this instance maps to.

public abstract int

Returns:

The year of this XMLGregorianCalendar.
getYear
()

Returns the low order component for XML Schema 1.0 dateTime datatype field for year or DatatypeConstants#FIELD_UNDEFINED.

public int

Returns:

hash code of this object.
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code consistent with the definition of the equals method.

public abstract boolean

Returns:

true if data values are valid.
isValid
()

Validate instance by getXMLSchemaType() constraints.

public abstract XMLGregorianCalendar

Returns:

this XMLGregorianCalendar normalized to UTC.
normalize
()

Normalize this instance to UTC.

public abstract void
reset()

Reset this XMLGregorianCalendar to its original values.

public abstract void
setDay(int
value constraints summarized in day field of date/time field mapping table.
day
)

Set days in month.

public abstract void
setFractionalSecond(BigDecimal
value constraints summarized in second field of date/time field mapping table.
fractional
)

Set fractional seconds.

public abstract void
setHour(int
value constraints summarized in hour field of date/time field mapping table.
hour
)

Set hours.

public abstract void
setMillisecond(int
value constraints summarized in second field of date/time field mapping table.
millisecond
)

Set milliseconds.

public abstract void
setMinute(int
value constraints summarized in minute field of date/time field mapping table.
minute
)

Set minutes.

public abstract void
setMonth(int
value constraints summarized in month field of date/time field mapping table.
month
)

Set month.

public abstract void
setSecond(int
value constraints summarized in second field of date/time field mapping table.
second
)

Set seconds.

public void
setTime(int
value constraints are summarized in hour field of date/time field mapping table.
hour
,
int
value constraints are summarized in minute field of date/time field mapping table.
minute
,
int
value constraints are summarized in second field of date/time field mapping table.
second
)

Set time as one unit.

public void
setTime(int
value constraints are summarized in hour field of date/time field mapping table.
hour
,
int
value constraints are summarized in minute field of date/time field mapping table.
minute
,
int
value constraints are summarized in second field of date/time field mapping table.
second
,
BigDecimal
value of null indicates this optional field is not set.
fractional
)

Set time as one unit, including the optional infinite precision fractional seconds.

public void
setTime(int
value constraints are summarized in hour field of date/time field mapping table.
hour
,
int
value constraints are summarized in minute field of date/time field mapping table.
minute
,
int
value constraints are summarized in second field of date/time field mapping table.
second
,
int
value of DatatypeConstants#FIELD_UNDEFINED indicates this optional field is not set.
millisecond
)

Set time as one unit, including optional milliseconds.

public abstract void
setTimezone(int
value constraints summarized in timezone field of date/time field mapping table.
offset
)

Set the number of minutes in the timezone offset.

public abstract void
setYear(BigInteger
value constraints summarized in year field of date/time field mapping table.
year
)

Set low and high order component of XSD dateTime year field.

public abstract void
setYear(int
value constraints are summarized in year field of date/time field mapping table. If year is DatatypeConstants#FIELD_UNDEFINED, then eon is set to null.
year
)

Set year of XSD dateTime year field.

public abstract GregorianCalendar

Returns:

An instance of java.util.GregorianCalendar.
toGregorianCalendar
()

Convert this XMLGregorianCalendar to a GregorianCalendar.

public abstract GregorianCalendar

Returns:

a java.util.GregorianCalendar conversion of this instance.
toGregorianCalendar
(TimeZone
provide Timezone. null is a legal value.
timezone
,
Locale
provide explicit Locale. Use default GregorianCalendar locale if value is null.
aLocale
,
XMLGregorianCalendar
provide default field values to use when corresponding field for this instance is FIELD_UNDEFINED or null. If defaultsis null or a field within the specified defaults is undefined, just use java.util.GregorianCalendar defaults.
defaults
)

Convert this XMLGregorianCalendar along with provided parameters to a GregorianCalendar instance.

public String

Returns:

A non-null valid String representation of this XMLGregorianCalendar.
toString
()

Overrides java.lang.Object.toString.

Returns a String representation of this XMLGregorianCalendar Object.

public abstract String

Returns:

XML, as String, representation of this XMLGregorianCalendar
toXMLFormat
()

Return the lexical representation of this instance.

Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait

Constructor Detail

XMLGregorianCalendarback to summary
public XMLGregorianCalendar()

Default no-arg constructor.

Note

Always use the DatatypeFactory to construct an instance of XMLGregorianCalendar. The constructor on this class cannot be guaranteed to produce an object with a consistent state and may be removed in the future.

Method Detail

addback to summary
public abstract void add(Duration duration)

Add duration to this instance.

The computation is specified in XML Schema 1.0 Part 2, Appendix E, Adding durations to dateTimes. date/time field mapping table defines the mapping from XML Schema 1.0 dateTime fields to this class' representation of those fields.

Parameters
duration:Duration

Duration to add to this XMLGregorianCalendar.

Exceptions
NullPointerException:
when duration parameter is null.
clearback to summary
public abstract void clear()

Unset all fields to undefined.

Set all int fields to DatatypeConstants#FIELD_UNDEFINED and reference fields to null.

cloneback to summary
public abstract Object clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.

Returns:Object

copy of this Object

Annotations
@Override
compareback to summary
public abstract int compare(XMLGregorianCalendar xmlGregorianCalendar)

Compare two instances of W3C XML Schema 1.0 date/time datatypes according to partial order relation defined in W3C XML Schema 1.0 Part 2, Section 3.2.7.3, Order relation on dateTime.

xsd:dateTime datatype field mapping to accessors of this class are defined in date/time field mapping table.

Parameters
xmlGregorianCalendar:XMLGregorianCalendar

Instance of XMLGregorianCalendar to compare

Returns:int

The relationship between this XMLGregorianCalendar and the specified xmlGregorianCalendar as DatatypeConstants#LESSER, DatatypeConstants#EQUAL, DatatypeConstants#GREATER or DatatypeConstants#INDETERMINATE.

Exceptions
NullPointerException:
if xmlGregorianCalendar is null.
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Compares this calendar to the specified object. The result is true if and only if the argument is not null and is an XMLGregorianCalendar object that represents the same instant in time as this object.

Parameters
obj:Object

to compare.

Returns:boolean

true when obj is an instance of XMLGregorianCalendar and compare(XMLGregorianCalendar obj) returns DatatypeConstants#EQUAL, otherwise false.

Annotations
@Override
getDayback to summary
public abstract int getDay()

Returns the day of month or DatatypeConstants#FIELD_UNDEFINED.

Value constraints for this value are summarized in day field of date/time field mapping table.

Returns:int

The day of month of this XMLGregorianCalendar, from 1 to 31.

See Also
setDay(int)
getEonback to summary
public abstract BigInteger getEon()

Returns the high order component for XML Schema 1.0 dateTime datatype field for year. null if this optional part of the year field is not defined.

Value constraints for this value are summarized in year field of date/time field mapping table.

Returns:BigInteger

The eon of this XMLGregorianCalendar. The value returned is an integer multiple of 10^9.

See Also
getYear(), getEonAndYear()
getEonAndYearback to summary
public abstract BigInteger getEonAndYear()

Returns the XML Schema 1.0 dateTime datatype field for year.

Value constraints for this value are summarized in year field of date/time field mapping table.

Returns:BigInteger

sum of eon and BigInteger.valueOf(year) when both fields are defined. When only year is defined, return it. When both eon and year are not defined, return null.

See Also
getEon(), getYear()
getFractionalSecondback to summary
public abstract BigDecimal getFractionalSecond()

Returns fractional seconds.

null is returned when this optional field is not defined.

Value constraints are detailed in second field of date/time field mapping table.

This optional field can only have a defined value when the xs:dateTime second field, represented by getSecond(), does not return DatatypeConstants#FIELD_UNDEFINED.

Returns:BigDecimal

Fractional seconds of this XMLGregorianCalendar.

See Also
getSecond(), setTime(int, int, int, BigDecimal)
getHourback to summary
public abstract int getHour()

Returns the hour of day or DatatypeConstants#FIELD_UNDEFINED if this field is not defined.

Value constraints for this value are summarized in hour field of date/time field mapping table.

Returns:int

The hour of day of this XMLGregorianCalendar, from 0 to 23.

See Also
setTime(int, int, int)
getMillisecondback to summary
public int getMillisecond()

Returns the millisecond precision of getFractionalSecond().

This method represents a convenience accessor to infinite precision fractional second value returned by getFractionalSecond(). The returned value is the rounded down to milliseconds value of getFractionalSecond(). When getFractionalSecond() returns null, this method must return DatatypeConstants#FIELD_UNDEFINED.

Value constraints for this value are summarized in second field of date/time field mapping table.

Returns:int

The millisecond precision of this XMLGregorianCalendar.

See Also
getFractionalSecond(), setTime(int, int, int)
getMinuteback to summary
public abstract int getMinute()

Returns the minute of hour or DatatypeConstants#FIELD_UNDEFINED if this field is not defined.

Value constraints for this value are summarized in minute field of date/time field mapping table.

Returns:int

The minute of hour of this XMLGregorianCalendar, from 0 to 59.

See Also
setTime(int, int, int)
getMonthback to summary
public abstract int getMonth()

Returns the month of this calendar or DatatypeConstants#FIELD_UNDEFINED.

Value constraints for this value are summarized in month field of date/time field mapping table.

Returns:int

The month of this XMLGregorianCalendar, from 1 to 12.

getSecondback to summary
public abstract int getSecond()

Returns the second of minute or DatatypeConstants#FIELD_UNDEFINED if this field is not defined. When this field is not defined, the optional xs:dateTime fractional seconds field, represented by getFractionalSecond() and getMillisecond(), must not be defined.

Value constraints for this value are summarized in second field of date/time field mapping table.

Returns:int

The second of minute of this XMLGregorianCalendar, from 0 to 59.

See Also
getFractionalSecond(), getMillisecond(), setTime(int, int, int)
getTimezoneback to summary
public abstract int getTimezone()

Returns the Timezone offset in minutes or DatatypeConstants#FIELD_UNDEFINED if this optional field is not defined.

Value constraints for this value are summarized in timezone field of date/time field mapping table.

Returns:int

The Timezone offset in minutes of this XMLGregorianCalendar.

See Also
setTimezone(int)
getTimeZoneback to summary
public abstract TimeZone getTimeZone(int defaultZoneoffset)

Returns a java.util.TimeZone for this class.

If timezone field is defined for this instance, returns TimeZone initialized with custom timezone id of zoneoffset. If timezone field is undefined, try the defaultZoneoffset that was passed in. If defaultZoneoffset is FIELD_UNDEFINED, return default timezone for this host. (Same default as java.util.GregorianCalendar).

Parameters
defaultZoneoffset:int

default zoneoffset if this zoneoffset is DatatypeConstants#FIELD_UNDEFINED.

Returns:TimeZone

TimeZone for this.

getXMLSchemaTypeback to summary
public abstract QName getXMLSchemaType()

Return the name of the XML Schema date/time type that this instance maps to. Type is computed based on fields that are set.

Required fields for XML Schema 1.0 Date/Time Datatypes.
(timezone is optional for all date/time datatypes)
Datatype year month day hour minute second
DatatypeConstants#DATETIME X X X X X X
DatatypeConstants#DATE X X X
DatatypeConstants#TIME X X X
DatatypeConstants#GYEARMONTH X X
DatatypeConstants#GMONTHDAY X X
DatatypeConstants#GYEAR X
DatatypeConstants#GMONTH X
DatatypeConstants#GDAY X
Returns:QName

One of the following class constants: DatatypeConstants#DATETIME, DatatypeConstants#TIME, DatatypeConstants#DATE, DatatypeConstants#GYEARMONTH, DatatypeConstants#GMONTHDAY, DatatypeConstants#GYEAR, DatatypeConstants#GMONTH or DatatypeConstants#GDAY.

Exceptions
IllegalStateException:
if the combination of set fields does not match one of the eight defined XML Schema builtin date/time datatypes.
getYearback to summary
public abstract int getYear()

Returns the low order component for XML Schema 1.0 dateTime datatype field for year or DatatypeConstants#FIELD_UNDEFINED.

Value constraints for this value are summarized in year field of date/time field mapping table.

Returns:int

The year of this XMLGregorianCalendar.

See Also
getEon(), getEonAndYear()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code consistent with the definition of the equals method.

Returns:int

hash code of this object.

Annotations
@Override
isValidback to summary
public abstract boolean isValid()

Validate instance by getXMLSchemaType() constraints.

Returns:boolean

true if data values are valid.

normalizeback to summary
public abstract XMLGregorianCalendar normalize()

Normalize this instance to UTC.

2000-03-04T23:00:00+03:00 normalizes to 2000-03-04T20:00:00Z

Implements W3C XML Schema Part 2, Section 3.2.7.3 (A).

Returns:XMLGregorianCalendar

this XMLGregorianCalendar normalized to UTC.

resetback to summary
public abstract void reset()

Reset this XMLGregorianCalendar to its original values.

XMLGregorianCalendar is reset to the same values as when it was created with DatatypeFactory#newXMLGregorianCalendar(), DatatypeFactory#newXMLGregorianCalendar(String lexicalRepresentation), DatatypeFactory#newXMLGregorianCalendar( BigInteger year, int month, int day, int hour, int minute, int second, BigDecimal fractionalSecond, int timezone), DatatypeFactory#newXMLGregorianCalendar( int year, int month, int day, int hour, int minute, int second, int millisecond, int timezone), DatatypeFactory#newXMLGregorianCalendar(GregorianCalendar cal), DatatypeFactory#newXMLGregorianCalendarDate( int year, int month, int day, int timezone), DatatypeFactory#newXMLGregorianCalendarTime( int hours, int minutes, int seconds, int timezone), DatatypeFactory#newXMLGregorianCalendarTime( int hours, int minutes, int seconds, BigDecimal fractionalSecond, int timezone) or DatatypeFactory#newXMLGregorianCalendarTime( int hours, int minutes, int seconds, int milliseconds, int timezone).

reset() is designed to allow the reuse of existing XMLGregorianCalendars thus saving resources associated with the creation of new XMLGregorianCalendars.

setDayback to summary
public abstract void setDay(int day)

Set days in month.

Unset this field by invoking the setter with a parameter value of DatatypeConstants#FIELD_UNDEFINED.

Parameters
day:int

value constraints summarized in day field of date/time field mapping table.

Exceptions
IllegalArgumentException:
if day parameter is outside value constraints for the field as specified in date/time field mapping table.
setFractionalSecondback to summary
public abstract void setFractionalSecond(BigDecimal fractional)

Set fractional seconds.

Unset this field by invoking the setter with a parameter value of null.

Parameters
fractional:BigDecimal

value constraints summarized in second field of date/time field mapping table.

Exceptions
IllegalArgumentException:
if fractional parameter is outside value constraints for the field as specified in date/time field mapping table.
setHourback to summary
public abstract void setHour(int hour)

Set hours.

Unset this field by invoking the setter with a parameter value of DatatypeConstants#FIELD_UNDEFINED.

Parameters
hour:int

value constraints summarized in hour field of date/time field mapping table.

Exceptions
IllegalArgumentException:
if hour parameter is outside value constraints for the field as specified in date/time field mapping table.
setMillisecondback to summary
public abstract void setMillisecond(int millisecond)

Set milliseconds.

Unset this field by invoking the setter with a parameter value of DatatypeConstants#FIELD_UNDEFINED.

Parameters
millisecond:int

value constraints summarized in second field of date/time field mapping table.

Exceptions
IllegalArgumentException:
if millisecond parameter is outside value constraints for the field as specified in date/time field mapping table.
setMinuteback to summary
public abstract void setMinute(int minute)

Set minutes.

Unset this field by invoking the setter with a parameter value of DatatypeConstants#FIELD_UNDEFINED.

Parameters
minute:int

value constraints summarized in minute field of date/time field mapping table.

Exceptions
IllegalArgumentException:
if minute parameter is outside value constraints for the field as specified in date/time field mapping table.
setMonthback to summary
public abstract void setMonth(int month)

Set month.

Unset this field by invoking the setter with a parameter value of DatatypeConstants#FIELD_UNDEFINED.

Parameters
month:int

value constraints summarized in month field of date/time field mapping table.

Exceptions
IllegalArgumentException:
if month parameter is outside value constraints for the field as specified in date/time field mapping table.
setSecondback to summary
public abstract void setSecond(int second)

Set seconds.

Unset this field by invoking the setter with a parameter value of DatatypeConstants#FIELD_UNDEFINED.

Parameters
second:int

value constraints summarized in second field of date/time field mapping table.

Exceptions
IllegalArgumentException:
if second parameter is outside value constraints for the field as specified in date/time field mapping table.
setTimeback to summary
public void setTime(int hour, int minute, int second)

Set time as one unit.

Parameters
hour:int

value constraints are summarized in hour field of date/time field mapping table.

minute:int

value constraints are summarized in minute field of date/time field mapping table.

second:int

value constraints are summarized in second field of date/time field mapping table.

Exceptions
IllegalArgumentException:
if any parameter is outside value constraints for the field as specified in date/time field mapping table.
See Also
setTime(int, int, int, BigDecimal)
setTimeback to summary
public void setTime(int hour, int minute, int second, BigDecimal fractional)

Set time as one unit, including the optional infinite precision fractional seconds.

Parameters
hour:int

value constraints are summarized in hour field of date/time field mapping table.

minute:int

value constraints are summarized in minute field of date/time field mapping table.

second:int

value constraints are summarized in second field of date/time field mapping table.

fractional:BigDecimal

value of null indicates this optional field is not set.

Exceptions
IllegalArgumentException:
if any parameter is outside value constraints for the field as specified in date/time field mapping table.
setTimeback to summary
public void setTime(int hour, int minute, int second, int millisecond)

Set time as one unit, including optional milliseconds.

Parameters
hour:int

value constraints are summarized in hour field of date/time field mapping table.

minute:int

value constraints are summarized in minute field of date/time field mapping table.

second:int

value constraints are summarized in second field of date/time field mapping table.

millisecond:int

value of DatatypeConstants#FIELD_UNDEFINED indicates this optional field is not set.

Exceptions
IllegalArgumentException:
if any parameter is outside value constraints for the field as specified in date/time field mapping table.
setTimezoneback to summary
public abstract void setTimezone(int offset)

Set the number of minutes in the timezone offset.

Unset this field by invoking the setter with a parameter value of DatatypeConstants#FIELD_UNDEFINED.

Parameters
offset:int

value constraints summarized in timezone field of date/time field mapping table.

Exceptions
IllegalArgumentException:
if offset parameter is outside value constraints for the field as specified in date/time field mapping table.
setYearback to summary
public abstract void setYear(BigInteger year)

Set low and high order component of XSD dateTime year field.

Unset this field by invoking the setter with a parameter value of null.

Parameters
year:BigInteger

value constraints summarized in year field of date/time field mapping table.

Exceptions
IllegalArgumentException:
if year parameter is outside value constraints for the field as specified in date/time field mapping table.
setYearback to summary
public abstract void setYear(int year)

Set year of XSD dateTime year field.

Unset this field by invoking the setter with a parameter value of DatatypeConstants#FIELD_UNDEFINED.

Note

if the absolute value of the year parameter is less than 10^9, the eon component of the XSD year field is set to null by this method.

Parameters
year:int

value constraints are summarized in year field of date/time field mapping table. If year is DatatypeConstants#FIELD_UNDEFINED, then eon is set to null.

toGregorianCalendarback to summary
public abstract GregorianCalendar toGregorianCalendar()

Convert this XMLGregorianCalendar to a 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 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 getEonAndYear().signum() < 0 ? GregorianCalendar.BC : GregorianCalendar.AD
YEAR getEonAndYear().abs().intValue()*
MONTH getMonth() - DatatypeConstants#JANUARY + GregorianCalendar#JANUARY
DAY_OF_MONTH getDay()
HOUR_OF_DAY getHour()
MINUTE getMinute()
SECOND getSecond()
MILLISECOND get millisecond order from getFractionalSecond()*
GregorianCalendar.setTimeZone(TimeZone) 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 java.util.GregorianCalendar#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)
Returns:GregorianCalendar

An instance of java.util.GregorianCalendar.

See Also
toGregorianCalendar(java.util.TimeZone, java.util.Locale, XMLGregorianCalendar)
toGregorianCalendarback to summary
public abstract GregorianCalendar toGregorianCalendar(TimeZone timezone, Locale aLocale, XMLGregorianCalendar defaults)

Convert this XMLGregorianCalendar along with provided parameters to a GregorianCalendar instance.

Since XML Schema 1.0 date/time datetypes has no concept of timezone ids or daylight savings timezone ids, this conversion operation allows the user to explicitly specify one with timezone parameter.

To compute the return value's TimeZone field,

  • when parameter timeZone is non-null, it is the timezone field.
  • else when this.getTimezone() != FIELD_UNDEFINED, create a java.util.TimeZone with a custom timezone id using the this.getTimezone().
  • else when defaults.getTimezone() != FIELD_UNDEFINED, create a java.util.TimeZone with a custom timezone id using defaults.getTimezone().
  • else use the GregorianCalendar default timezone value for the host is defined as specified by java.util.TimeZone.getDefault().

To ensure consistency in conversion implementations, the new GregorianCalendar should be instantiated in following manner.

  • Create a new java.util.GregorianCalendar(TimeZone, Locale) with TimeZone set as specified above and the Locale parameter.
  • Initialize all GregorianCalendar fields by calling GregorianCalendar#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)
Parameters
timezone:TimeZone

provide Timezone. null is a legal value.

aLocale:Locale

provide explicit Locale. Use default GregorianCalendar locale if value is null.

defaults:XMLGregorianCalendar

provide default field values to use when corresponding field for this instance is FIELD_UNDEFINED or null. If defaultsis null or a field within the specified defaults is undefined, just use java.util.GregorianCalendar defaults.

Returns:GregorianCalendar

a java.util.GregorianCalendar conversion of this instance.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a String representation of this XMLGregorianCalendar Object.

The result is a lexical representation generated by toXMLFormat().

Returns:String

A non-null valid String representation of this XMLGregorianCalendar.

Annotations
@Override
Exceptions
IllegalStateException:
if the combination of set fields does not match one of the eight defined XML Schema builtin date/time datatypes.
See Also
toXMLFormat()
toXMLFormatback to summary
public abstract String toXMLFormat()

Return the lexical representation of this instance. The format is specified in XML Schema 1.0 Part 2, Section 3.2.[7-14].1, Lexical Representation".

Specific target lexical representation format is determined by getXMLSchemaType().

Returns:String

XML, as String, representation of this XMLGregorianCalendar

Exceptions
IllegalStateException:
if the combination of set fields does not match one of the eight defined XML Schema builtin date/time datatypes.