本文整理匯總了Java中javax.xml.datatype.XMLGregorianCalendar.setYear方法的典型用法代碼示例。如果您正苦於以下問題:Java XMLGregorianCalendar.setYear方法的具體用法?Java XMLGregorianCalendar.setYear怎麽用?Java XMLGregorianCalendar.setYear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.datatype.XMLGregorianCalendar
的用法示例。
在下文中一共展示了XMLGregorianCalendar.setYear方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toXMLCalendar
import javax.xml.datatype.XMLGregorianCalendar; //導入方法依賴的package包/類
public XMLGregorianCalendar toXMLCalendar(Date d) throws Exception {
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(d);
XMLGregorianCalendar xml = DatatypeFactory.newInstance()
.newXMLGregorianCalendar();
xml.setYear(gc.get(Calendar.YEAR));
xml.setMonth(gc.get(Calendar.MONTH) + 1);
xml.setDay(gc.get(Calendar.DAY_OF_MONTH));
xml.setHour(gc.get(Calendar.HOUR_OF_DAY));
xml.setMinute(gc.get(Calendar.MINUTE));
xml.setSecond(gc.get(Calendar.SECOND));
return xml;
}
示例2: checkIsValid
import javax.xml.datatype.XMLGregorianCalendar; //導入方法依賴的package包/類
@Test(dataProvider = "gMonth")
public void checkIsValid(String month) {
XMLGregorianCalendar gMonth = datatypeFactory.newXMLGregorianCalendar(month);
gMonth.setYear(null);
Assert.assertTrue(gMonth.isValid(), gMonth.toString() + " should isValid");
}
示例3: checkToGregorianCalendar01
import javax.xml.datatype.XMLGregorianCalendar; //導入方法依賴的package包/類
@Test
public void checkToGregorianCalendar01() {
XMLGregorianCalendar time_16_17_18 = datatypeFactory.newXMLGregorianCalendar("16:17:18");
XMLGregorianCalendar date_2001_02_03 = datatypeFactory.newXMLGregorianCalendar("2001-02-03");
GregorianCalendar calendar = date_2001_02_03.toGregorianCalendar(null, null, time_16_17_18);
int year = calendar.get(YEAR);
int minute = calendar.get(MINUTE);
assertTrue((year == 2001 && minute == 17), " expecting year == 2001, minute == 17" + ", result is year == " + year + ", minute == " + minute);
calendar = time_16_17_18.toGregorianCalendar(null, null, date_2001_02_03);
year = calendar.get(YEAR);
minute = calendar.get(MINUTE);
assertTrue((year == 2001 && minute == 17), " expecting year == 2001, minute == 17" + ", result is year == " + year + ", minute == " + minute);
date_2001_02_03.setMinute(3);
date_2001_02_03.setYear(null);
XMLGregorianCalendar date_time = datatypeFactory.newXMLGregorianCalendar("2003-04-11T02:13:01Z");
calendar = date_2001_02_03.toGregorianCalendar(null, null, date_time);
year = calendar.get(YEAR);
minute = calendar.get(MINUTE);
int hour = calendar.get(HOUR);
assertTrue((year == 2003 && hour == 2 && minute == 3), " expecting year == 2003, hour == 2, minute == 3" + ", result is year == " + year + ", hour == " + hour + ", minute == " + minute);
}