Most visited

Recently visited

Added in API level 8

XMLGregorianCalendar

public abstract class XMLGregorianCalendar
extends Object implements Cloneable

java.lang.Object
   ↳ javax.xml.datatype.XMLGregorianCalendar


W3C XML Schema 1.0日期/时间数据类型的表示形式。 具体而言,这些日期/时间数据类型是dateTimetimedategYearMonthgMonthDaygYear gMonthgDay在XML命名空间定义"http://www.w3.org/2001/XMLSchema" 这些数据类型在W3C XML Schema 1.0 Part 2, Section 3.2.7-14中进行了规范定义。

下表定义了XML Schema 1.0日期/时间数据类型字段与此类的字段之间的映射。 它还总结了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 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 FIELD_UNDEFINED
day getDay() Independent of month, max range is 1 to 31 or 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 24 or FIELD_UNDEFINED. For a value of 24, the minute and second field must be zero per XML Schema Errata.
minute getMinute() 0 to 59 or FIELD_UNDEFINED
second getSecond() + getMillisecond()/1000 or
getSecond() + getFractionalSecond()
getSecond() from 0 to 60 or 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 FIELD_UNDEFINED. Value range from -14 hours (-14 * 60 minutes) to 14 hours (14 * 60 minutes).

列出的上表中所有字段的最大值空间约束均由该类的工厂方法@ {link DatatypeFactory},setter方法和解析方法进行检查。 当参数的值超出字段的值约束或者如果组合值构成无效的XMLGregorianCalendar实例(例如,如果指定了6月31日),则会引发IllegalArgumentException

以下操作是为这个类定义的:

也可以看看:

Summary

Public constructors

XMLGregorianCalendar()

Public methods

abstract void add(Duration duration)

duration添加到此实例。

abstract void clear()

取消将所有字段设置为未定义。

abstract Object clone()

创建并返回此对象的副本。

abstract int compare(XMLGregorianCalendar xmlGregorianCalendar)

根据 W3C XML Schema 1.0 Part 2, Section 3.2.7.3, Order relation on dateTime定义的部分顺序关系比较W3C XML Schema 1 . 0日期/时间数据类型的两个实例。

boolean equals(Object obj)

指示参数 obj是否“等于”这一个。

abstract int getDay()

每月返回一天或 FIELD_UNDEFINED

abstract BigInteger getEon()

针对 year返回XML Schema 1.0 dateTime数据类型字段的 year

abstract BigInteger getEonAndYear()

返回XML Schema 1.0 dateTime数据类型字段为 year

abstract BigDecimal getFractionalSecond()

返回小数秒。

abstract int getHour()

返回小时或 FIELD_UNDEFINED

int getMillisecond()

返回毫秒精度 getFractionalSecond()

abstract int getMinute()

返回分钟或 FIELD_UNDEFINED

abstract int getMonth()

返回月数或 FIELD_UNDEFINED

abstract int getSecond()

返回秒或 FIELD_UNDEFINED

abstract TimeZone getTimeZone(int defaultZoneoffset)

返回 java.util.TimeZone

abstract int getTimezone()

如果 FIELD_UNDEFINED此可选字段, FIELD_UNDEFINED分钟或 FIELD_UNDEFINED返回时区偏移量。

abstract QName getXMLSchemaType()

返回此实例映射到的XML模式日期/时间类型的名称。

abstract int getYear()

yearFIELD_UNDEFINED返回XML Schema 1.0 dateTime数据类型字段的 year FIELD_UNDEFINED

int hashCode()

返回与equals方法的定义一致的散列码。

abstract boolean isValid()

通过 getXMLSchemaType()约束验证实例。

abstract XMLGregorianCalendar normalize()

将此实例标准化为UTC。

abstract void reset()

将此 XMLGregorianCalendar重置为其原始值。

abstract void setDay(int day)

按月设置日期。

abstract void setFractionalSecond(BigDecimal fractional)

设置小数秒。

abstract void setHour(int hour)

设置小时。

abstract void setMillisecond(int millisecond)

设置毫秒。

abstract void setMinute(int minute)

设置分钟。

abstract void setMonth(int month)

设置月份。

abstract void setSecond(int second)

设置秒。

void setTime(int hour, int minute, int second, BigDecimal fractional)

将时间设置为一个单位,包括可选的无限精度小数秒。

void setTime(int hour, int minute, int second)

将时间设置为一个单位。

void setTime(int hour, int minute, int second, int millisecond)

将时间设置为一个单位,包括可选的毫秒。

abstract void setTimezone(int offset)

设置时区偏移中的分钟数。

abstract void setYear(BigInteger year)

设置XSD dateTime年份字段的低阶和高阶部分。

abstract void setYear(int year)

设置XSD dateTime年份字段的年份。

abstract GregorianCalendar toGregorianCalendar()

将此 XMLGregorianCalendar转换为 GregorianCalendar

abstract GregorianCalendar toGregorianCalendar(TimeZone timezone, Locale aLocale, XMLGregorianCalendar defaults)

将此 XMLGregorianCalendar连同提供的参数一起转换为 GregorianCalendar实例。

String toString()

返回此 XMLGregorianCalendar ObjectString表示 Object

abstract String toXMLFormat()

返回 this实例的词汇表示。

Inherited methods

From class java.lang.Object

Public constructors

XMLGregorianCalendar

Added in API level 8
XMLGregorianCalendar ()

Public methods

add

Added in API level 8
void add (Duration duration)

duration添加到此实例。

计算在XML Schema 1.0 Part 2, Appendix E, Adding durations to dateTimes>中指定。 date/time field mapping table定义了从XML Schema 1.0 dateTime字段到该类的这些字段表示的映射。

Parameters
duration Duration: Duration to add to this XMLGregorianCalendar.
Throws
NullPointerException when duration parameter is null.

clear

Added in API level 8
void clear ()

取消将所有字段设置为未定义。

将所有int字段设置为 FIELD_UNDEFINED并将引用字段设置为null。

clone

Added in API level 8
Object clone ()

创建并返回此对象的副本。

Returns
Object copy of this Object

compare

Added in API level 8
int compare (XMLGregorianCalendar xmlGregorianCalendar)

根据 W3C XML Schema 1.0 Part 2, Section 3.2.7.3, Order relation on dateTime定义的部分顺序关系比较W3C XML Schema 1 . 0日期/时间数据类型的两个实例。

xsd:dateTime数据类型字段映射到此类的访问器在 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 LESSER, EQUAL, GREATER or INDETERMINATE.
Throws
NullPointerException if xmlGregorianCalendar is null.

equals

Added in API level 8
boolean equals (Object obj)

指示参数 obj是否“等于”这一个。

Parameters
obj Object: to compare.
Returns
boolean true when obj is an instance of XMLGregorianCalendar and compare(XMLGregorianCalendar) returns EQUAL, otherwise false.

getDay

Added in API level 8
int getDay ()

每月返回一天或 FIELD_UNDEFINED

该值的值限制总结在 day field of date/time field mapping table中

Returns
int

也可以看看:

getEon

Added in API level 8
BigInteger getEon ()

year返回XML Schema 1.0 dateTime数据类型字段的year null如果这个年份字段的这个可选部分没有定义。

year field of date/time field mapping table中汇总了此值的值限制。

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

也可以看看:

getEonAndYear

Added in API level 8
BigInteger getEonAndYear ()

返回XML Schema 1.0 dateTime数据类型字段为 year

这个值的价值限制总结在 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.

也可以看看:

getFractionalSecond

Added in API level 8
BigDecimal getFractionalSecond ()

返回小数秒。

null此可选字段时将返回 null

价值限制详见 second field of date/time field mapping table

当xs:dateTime第二个字段(由 getSecond()表示)不返回 FIELD_UNDEFINED时,此可选字段只能有一个定义的值。

Returns
BigDecimal fractional seconds of this XMLGregorianCalendar.

也可以看看:

getHour

Added in API level 8
int getHour ()

返回小时或FIELD_UNDEFINED 如果此字段FIELD_UNDEFINED则返回FIELD_UNDEFINED

hour field of date/time field mapping table中汇总了此值的限制值。

Returns
int

也可以看看:

getMillisecond

Added in API level 8
int getMillisecond ()

返回毫秒级精度 getFractionalSecond()

此方法表示一个方便的访问器,以无限精度分数秒值返回getFractionalSecond() 返回的值是舍入到毫秒getFractionalSecond()值。 getFractionalSecond()返回null ,此方法必须返回FIELD_UNDEFINED

second field of date/time field mapping table中总结了此值的值限制。

Returns
int Millisecond of this XMLGregorianCalendar.

也可以看看:

getMinute

Added in API level 8
int getMinute ()

返回分钟或 FIELD_UNDEFINED

Returns FIELD_UNDEFINED if this field is not defined.

这个值的价值限制总结在 minute field of date/time field mapping table

Returns
int

也可以看看:

getMonth

Added in API level 8
int getMonth ()

返回月数或 FIELD_UNDEFINED

该值的值限制总结在 month field of date/time field mapping table中

Returns
int year of this XMLGregorianCalendar.

getSecond

Added in API level 8
int getSecond ()

返回秒或 FIELD_UNDEFINED

如果未定义此字段,则返回FIELD_UNDEFINED 未定义此字段时,不能定义可选的xs:dateTime小数秒字段(由getFractionalSecond()getMillisecond()表示)。

second field of date/time field mapping table中总结了此值的价值限制。

Returns
int Second of this XMLGregorianCalendar.

也可以看看:

getTimeZone

Added in API level 8
TimeZone getTimeZone (int defaultZoneoffset)

返回 java.util.TimeZone

如果为此实例定义时区字段,则返回使用zoneoffset的自定义时区ID初始化的TimeZone。 如果时区字段未定义,请尝试传入的defaultZoneoffset。如果defaultZoneoffset为FIELD_UNDEFINED,则返回此主机的默认时区。 (与java.util.GregorianCalendar相同)。

Parameters
defaultZoneoffset int: default zoneoffset if this zoneoffset is FIELD_UNDEFINED.
Returns
TimeZone TimeZone for this.

getTimezone

Added in API level 8
int getTimezone ()

如果 FIELD_UNDEFINED此可选字段, FIELD_UNDEFINED分钟或 FIELD_UNDEFINED返回时区偏移量。

timezone field of date/time field mapping table中汇总了此值的值限制。

Returns
int

也可以看看:

getXMLSchemaType

Added in API level 8
QName getXMLSchemaType ()

返回此实例映射到的XML模式日期/时间类型的名称。 类型根据设置的字段进行计算。

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
DATETIME X X X X X X
DATE X X X
TIME X X X
GYEARMONTH X X
GMONTHDAY X X
GYEAR X
GMONTH X
GDAY X

Returns
QName One of the following class constants: DATETIME, TIME, DATE, GYEARMONTH, GMONTHDAY, GYEAR, GMONTH or GDAY.
Throws
IllegalStateException if the combination of set fields does not match one of the eight defined XML Schema builtin date/time datatypes.

getYear

Added in API level 8
int getYear ()

返回XML Schema 1.0 dateTime数据类型字段为 yearFIELD_UNDEFINED

year field of date/time field mapping table中总结了此值的值限制。

Returns
int year of this XMLGregorianCalendar.

也可以看看:

hashCode

Added in API level 8
int hashCode ()

返回与equals方法的定义一致的散列码。

Returns
int hash code of this object.

isValid

Added in API level 8
boolean isValid ()

通过 getXMLSchemaType()约束验证实例。

Returns
boolean true if data values are valid.

normalize

Added in API level 8
XMLGregorianCalendar normalize ()

将此实例标准化为UTC。

2000-03-04T23:00:00 + 03:00正常化为2000-03-04T20:00:00Z

实现W3C XML Schema第2部分,第3.2.7.3(A)节。

Returns
XMLGregorianCalendar this XMLGregorianCalendar normalized to UTC.

reset

Added in API level 8
void reset ()

将此 XMLGregorianCalendar重置为其原始值。

XMLGregorianCalendar复位到当它被与创建为相同的值 newXMLGregorianCalendar()newXMLGregorianCalendar(String)newXMLGregorianCalendar(BigInteger, int, int, int, int, int, BigDecimal, int)newXMLGregorianCalendar(int, int, int, int, int, int, int, int)newXMLGregorianCalendar(GregorianCalendar)newXMLGregorianCalendarDate(int, int, int, int)newXMLGregorianCalendarTime(int, int, int, int)newXMLGregorianCalendarTime(int, int, int, BigDecimal, int)newXMLGregorianCalendarTime(int, int, int, int, int)

reset()旨在允许重复使用现有的 XMLGregorianCalendar从而节省与创建新的 XMLGregorianCalendar相关的资源。

setDay

Added in API level 8
void setDay (int day)

按月设置日期。

通过调用参数值为 FIELD_UNDEFINED的setter来取消设置此字段。

Parameters
day int: value constraints summarized in day field of date/time field mapping table.
Throws
IllegalArgumentException if day parameter is outside value constraints for the field as specified in date/time field mapping table.

setFractionalSecond

Added in API level 8
void setFractionalSecond (BigDecimal fractional)

设置小数秒。

通过调用参数值为 null的setter来取消设置此字段。

Parameters
fractional BigDecimal: value constraints summarized in fractional field of date/time field mapping table.
Throws
IllegalArgumentException if fractional parameter is outside value constraints for the field as specified in date/time field mapping table.

setHour

Added in API level 8
void setHour (int hour)

设置小时。

通过调用参数值为 FIELD_UNDEFINED的setter来取消设置此字段。

Parameters
hour int: value constraints summarized in hour field of date/time field mapping table.
Throws
IllegalArgumentException if hour parameter is outside value constraints for the field as specified in date/time field mapping table.

setMillisecond

Added in API level 8
void setMillisecond (int millisecond)

设置毫秒。

通过调用参数值为 FIELD_UNDEFINED的setter来取消设置此字段。

Parameters
millisecond int: value constraints summarized in millisecond field of date/time field mapping table.
Throws
IllegalArgumentException if millisecond parameter is outside value constraints for the field as specified in date/time field mapping table.

setMinute

Added in API level 8
void setMinute (int minute)

设置分钟。

通过调用带有参数值 FIELD_UNDEFINED的setter来取消设置此字段。

Parameters
minute int: value constraints summarized in minute field of date/time field mapping table.
Throws
IllegalArgumentException if minute parameter is outside value constraints for the field as specified in date/time field mapping table.

setMonth

Added in API level 8
void setMonth (int month)

设置月份。

通过调用参数值为 FIELD_UNDEFINED的setter来取消设置此字段。

Parameters
month int: value constraints summarized in month field of date/time field mapping table.
Throws
IllegalArgumentException if month parameter is outside value constraints for the field as specified in date/time field mapping table.

setSecond

Added in API level 8
void setSecond (int second)

设置秒。

通过调用参数值为 FIELD_UNDEFINED的setter来取消设置此字段。

Parameters
second int: value constraints summarized in second field of date/time field mapping table.
Throws
IllegalArgumentException if second parameter is outside value constraints for the field as specified in date/time field mapping table.

setTime

Added in API level 8
void setTime (int hour, 
                int minute, 
                int second, 
                BigDecimal fractional)

将时间设置为一个单位,包括可选的无限精度小数秒。

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.
Throws
IllegalArgumentException if any parameter is outside value constraints for the field as specified in date/time field mapping table.

setTime

Added in API level 8
void setTime (int hour, 
                int minute, 
                int second)

将时间设置为一个单位。

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.
Throws
IllegalArgumentException if any parameter is outside value constraints for the field as specified in date/time field mapping table.

也可以看看:

setTime

Added in API level 8
void setTime (int hour, 
                int minute, 
                int second, 
                int millisecond)

将时间设置为一个单位,包括可选的毫秒。

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 FIELD_UNDEFINED indicates this optional field is not set.
Throws
IllegalArgumentException if any parameter is outside value constraints for the field as specified in date/time field mapping table.

setTimezone

Added in API level 8
void setTimezone (int offset)

设置时区偏移中的分钟数。

通过调用参数值为 FIELD_UNDEFINED的setter来取消设置此字段。

Parameters
offset int: value constraints summarized in timezone field of date/time field mapping table.
Throws
IllegalArgumentException if offset parameter is outside value constraints for the field as specified in date/time field mapping table.

setYear

Added in API level 8
void setYear (BigInteger year)

设置XSD dateTime年份字段的低位和高位组件。

通过调用参数值为 null的setter来取消设置此字段。

Parameters
year BigInteger: value constraints summarized in year field of date/time field mapping table.
Throws
IllegalArgumentException if year parameter is outside value constraints for the field as specified in date/time field mapping table.

setYear

Added in API level 8
void setYear (int year)

设置XSD dateTime年份字段的年份。

通过调用带有参数值 FIELD_UNDEFINED的setter来取消设置此字段。

注意:如果 year参数的绝对值小于10 ^ 9,则通过此方法将XSD年份字段的eon组件设置为 null

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

toGregorianCalendar

Added in API level 8
GregorianCalendar toGregorianCalendar ()

将此 XMLGregorianCalendar转换为 GregorianCalendar

this实例具有未定义的字段时,此转换依赖于其相应字段的默认值java.util.GregorianCalendar XML Schema 1. java.util.GregorianCalendar期/时间数据类型和java.util.GregorianCalendar之间的显着区别在于时区值对于日期/时间数据类型是可选的,并且它是java.util.GregorianCalendar的必填字段。 有关如何确定默认值,请参阅javadoc获取java.util.TimeZone.getDefault() 要明确指定TimeZone实例,请参阅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() - JANUARY + 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.

为确保转换实现的一致性,应该按照以下方式实例化新的 GregorianCalendar

  • 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)

Returns
GregorianCalendar

也可以看看:

toGregorianCalendar

Added in API level 8
GregorianCalendar toGregorianCalendar (TimeZone timezone, 
                Locale aLocale, 
                XMLGregorianCalendar defaults)

将此 XMLGregorianCalendar与提供的参数一起转换为 GregorianCalendar实例。

由于XML Schema 1.0 date / time datetypes没有时区id或夏时制时区id的概念,因此此转换操作允许用户明确指定一个带 timezone参数的参数。

要计算返回值的 TimeZone字段,

  • 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().

为确保转换实现的一致性,应该按照以下方式实例化新的 GregorianCalendar

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

toString

Added in API level 8
String toString ()

返回此 XMLGregorianCalendar ObjectString表示 Object

结果是由 toXMLFormat()生成的词汇表示。

Returns
String A non-null valid String representation of this XMLGregorianCalendar.
Throws
IllegalStateException if the combination of set fields does not match one of the eight defined XML Schema builtin date/time datatypes.

也可以看看:

toXMLFormat

Added in API level 8
String toXMLFormat ()

返回this实例的词汇表示。 格式在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
Throws
IllegalStateException if the combination of set fields does not match one of the eight defined XML Schema builtin date/time datatypes.

Hooray!