本文整理汇总了Java中javax.xml.datatype.XMLGregorianCalendar.getYear方法的典型用法代码示例。如果您正苦于以下问题:Java XMLGregorianCalendar.getYear方法的具体用法?Java XMLGregorianCalendar.getYear怎么用?Java XMLGregorianCalendar.getYear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.datatype.XMLGregorianCalendar
的用法示例。
在下文中一共展示了XMLGregorianCalendar.getYear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hashCode
import javax.xml.datatype.XMLGregorianCalendar; //导入方法依赖的package包/类
/**
* <p>Returns a hash code consistent with the definition of the equals method.</p>
*
* @return hash code of this object.
*/
public int hashCode() {
// Following two dates compare to EQUALS since in different timezones.
// 2000-01-15T12:00:00-05:00 == 2000-01-15T13:00:00-04:00
//
// Must ensure both instances generate same hashcode by normalizing
// this to UTC timezone.
int timezone = getTimezone();
if (timezone == DatatypeConstants.FIELD_UNDEFINED) {
timezone = 0;
}
XMLGregorianCalendar gc = this;
if (timezone != 0) {
gc = this.normalizeToTimezone(getTimezone());
}
return gc.getYear() + gc.getMonth() + gc.getDay() +
gc.getHour() + gc.getMinute() + gc.getSecond();
}
示例2: test
import javax.xml.datatype.XMLGregorianCalendar; //导入方法依赖的package包/类
@Test
public void test() throws DatatypeConfigurationException {
DatatypeFactory dtf = DatatypeFactory.newInstance();
XMLGregorianCalendar c1 = dtf.newXMLGregorianCalendar("1999-12-31T24:00:00");
XMLGregorianCalendar c2 = dtf.newXMLGregorianCalendar("2000-01-01T00:00:00");
System.out.println("c1: " + c1.getYear() + "-" + c1.getMonth() + "-" + c1.getDay() + "T" + c1.getHour());
System.out.println(c1.equals(c2) ? "pass" : "fail"); // fails
if (!c1.equals(c2))
Assert.fail("hour 24 needs to be treated as equal to hour 0 of the next day");
if (c1.getYear() != 2000 && c1.getHour() != 0)
Assert.fail("hour 24 needs to be treated as equal to hour 0 of the next day");
}
示例3: checkXmlGregorianCalendarFieldRef
import javax.xml.datatype.XMLGregorianCalendar; //导入方法依赖的package包/类
private static void checkXmlGregorianCalendarFieldRef(QName type,
XMLGregorianCalendar cal)throws javax.xml.bind.MarshalException{
StringBuilder buf = new StringBuilder();
int bitField = xmlGregorianCalendarFieldRef.get(type);
final int l = 0x1;
int pos = 0;
while (bitField != 0x0){
int bit = bitField & l;
bitField >>>= 4;
pos++;
if (bit == 1) {
switch(pos){
case 1:
if (cal.getSecond() == DatatypeConstants.FIELD_UNDEFINED){
buf.append(" ").append(Messages.XMLGREGORIANCALENDAR_SEC);
}
break;
case 2:
if (cal.getMinute() == DatatypeConstants.FIELD_UNDEFINED){
buf.append(" ").append(Messages.XMLGREGORIANCALENDAR_MIN);
}
break;
case 3:
if (cal.getHour() == DatatypeConstants.FIELD_UNDEFINED){
buf.append(" ").append(Messages.XMLGREGORIANCALENDAR_HR);
}
break;
case 4:
if (cal.getDay() == DatatypeConstants.FIELD_UNDEFINED){
buf.append(" ").append(Messages.XMLGREGORIANCALENDAR_DAY);
}
break;
case 5:
if (cal.getMonth() == DatatypeConstants.FIELD_UNDEFINED){
buf.append(" ").append(Messages.XMLGREGORIANCALENDAR_MONTH);
}
break;
case 6:
if (cal.getYear() == DatatypeConstants.FIELD_UNDEFINED){
buf.append(" ").append(Messages.XMLGREGORIANCALENDAR_YEAR);
}
break;
case 7: // ignore timezone setting
break;
}
}
}
if (buf.length() > 0){
throw new javax.xml.bind.MarshalException(
Messages.XMLGREGORIANCALENDAR_INVALID.format(type.getLocalPart())
+ buf.toString());
}
}