本文整理匯總了Java中javax.xml.datatype.DatatypeFactory.newXMLGregorianCalendar方法的典型用法代碼示例。如果您正苦於以下問題:Java DatatypeFactory.newXMLGregorianCalendar方法的具體用法?Java DatatypeFactory.newXMLGregorianCalendar怎麽用?Java DatatypeFactory.newXMLGregorianCalendar使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.datatype.DatatypeFactory
的用法示例。
在下文中一共展示了DatatypeFactory.newXMLGregorianCalendar方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getXMLGregorianCalendarNow
import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
private XMLGregorianCalendar getXMLGregorianCalendarNow()
throws DatatypeConfigurationException {
GregorianCalendar gregorianCalendar = new GregorianCalendar();
DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
XMLGregorianCalendar now = datatypeFactory
.newXMLGregorianCalendar(gregorianCalendar);
return now;
}
示例2: convert2XMLCalendar
import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
public static XMLGregorianCalendar convert2XMLCalendar(Calendar calendar) {
try {
DatatypeFactory dtf = DatatypeFactory.newInstance();
return dtf.newXMLGregorianCalendar(
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH) + 1,
calendar.get(Calendar.DAY_OF_MONTH),
calendar.get(Calendar.HOUR),
calendar.get(Calendar.MINUTE),
calendar.get(Calendar.SECOND),
calendar.get(Calendar.MILLISECOND),
calendar.get(Calendar.ZONE_OFFSET) / (1000 * 60));
} catch (DatatypeConfigurationException e) {
e.printStackTrace();
return null;
}
}
示例3: newXMLGregorianCalendarSystemTime
import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
/**
*
* @return An object of type XMLGregorianCalendar containing the current
* system time and date
* @throws DatatypeConfigurationException
* If the instantiation of the DatatypeFactory fails
*/
public static XMLGregorianCalendar newXMLGregorianCalendarSystemTime()
throws DatatypeConfigurationException {
GregorianCalendar gregorianCalendar = new GregorianCalendar();
DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
XMLGregorianCalendar now = datatypeFactory
.newXMLGregorianCalendar(gregorianCalendar);
return now;
}
示例4: main
import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
/**
* main method.
*
* @param args Standard args.
*/
public static void main(String[] args) {
try {
String dateTimeString = "2006-11-22T00:00:00.0+01:02";
DatatypeFactory dtf = DatatypeFactory.newInstance();
XMLGregorianCalendar cal = dtf.newXMLGregorianCalendar( dateTimeString );
System.out.println( "XMLGregCal:" + cal.toString() );
System.out.println( "GregCal:" + cal.toGregorianCalendar() );
String toGCal = cal.toGregorianCalendar().toString();
if (toGCal.indexOf("GMT+12:00") > -1) {
throw new RuntimeException("Expected GMT+01:02");
}
} catch (DatatypeConfigurationException ex) {
throw new RuntimeException(ex.getMessage());
}
}
示例5: main
import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
/**
* main method.
*
* @param args Standard args.
*/
public static void main(String[] args) {
try {
String dateTimeString = "0001-01-01T00:00:00.0000000-05:00";
DatatypeFactory dtf = DatatypeFactory.newInstance();
XMLGregorianCalendar cal = dtf.newXMLGregorianCalendar( dateTimeString );
System.out.println( "Expected: 0001-01-01T00:00:00.0000000-05:00");
System.out.println( "Actual:" + cal.toString() );
System.out.println( "toXMLFormat:" + cal.toXMLFormat() );
String test = cal.toString();
if (test.indexOf("E-7") > -1) {
throw new RuntimeException("Expected: 0001-01-01T00:00:00.0000000-05:00");
}
} catch (DatatypeConfigurationException ex) {
throw new RuntimeException(ex.getMessage());
}
}
示例6: giveMeCalendarForNow
import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
/**
* To get a XMLGregorianCalendar for now
* @return a XMLGregorianCalendar for now
* @throws DatatypeConfigurationException if it can't create a calendar
*/
public static XMLGregorianCalendar giveMeCalendarForNow() throws DatatypeConfigurationException {
GregorianCalendar gregorianCalendar = new GregorianCalendar();
gregorianCalendar.setTime(new Date());
XMLGregorianCalendar result = null;
DatatypeFactory factory = DatatypeFactory.newInstance();
result = factory.newXMLGregorianCalendar(
gregorianCalendar.get(GregorianCalendar.YEAR),
gregorianCalendar.get(GregorianCalendar.MONTH) + 1,
gregorianCalendar.get(GregorianCalendar.DAY_OF_MONTH),
gregorianCalendar.get(GregorianCalendar.HOUR_OF_DAY),
gregorianCalendar.get(GregorianCalendar.MINUTE),
gregorianCalendar.get(GregorianCalendar.SECOND),
gregorianCalendar.get(GregorianCalendar.MILLISECOND), 0);
return result;
}
示例7: getXMLGregorianCalendar
import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
public static XMLGregorianCalendar getXMLGregorianCalendar(Date date) {
if (date == null) {
return null;
}
// Calendar calendar = Calendar.getInstance();
// calendar.setTimeInMillis(date.getTime());
DatatypeFactory datatypeFactory;
try {
datatypeFactory = DatatypeFactory.newInstance();
} catch (DatatypeConfigurationException e) {
throw new RuntimeException("Failed to create XMLGregorianCalendar: " + e, e);
}
GregorianCalendar c = new GregorianCalendar();
c.setTime(date);
return datatypeFactory.newXMLGregorianCalendar(c);
//
// XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory.newXMLGregorianCalendar();
// xmlGregorianCalendar.setYear(calendar.get(Calendar.YEAR));
// xmlGregorianCalendar.setMonth(calendar.get(Calendar.MONTH) + 1);
// xmlGregorianCalendar.setDay(calendar.get(Calendar.DAY_OF_MONTH));
// xmlGregorianCalendar.setHour(calendar.get(Calendar.HOUR_OF_DAY));
// xmlGregorianCalendar.setMinute(calendar.get(Calendar.MINUTE));
// xmlGregorianCalendar.setSecond(calendar.get(Calendar.SECOND));
// xmlGregorianCalendar.setMillisecond(calendar.get(Calendar.MILLISECOND));
// //
// xmlGregorianCalendar.setTimezone(calendar.get(((Calendar.DST_OFFSET)+calendar.get(Calendar.ZONE_OFFSET))/(60*1000)));
// return xmlGregorianCalendar;
}
示例8: applyOutages
import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
public AppliedOutages applyOutages(Calendar calendar, boolean assumeConnected) {
appliedOutages = ModelParser.applyOutages(calendar, rdfModel, assumeConnected);
GregorianCalendar gregorianCalendar = new GregorianCalendar();
gregorianCalendar.setTime(appliedOutages.getEffectiveEnd().getTime());
try {
DatatypeFactory factory = DatatypeFactory.newInstance();
endDate = factory.newXMLGregorianCalendar(gregorianCalendar);
Duration oneSecond = factory.newDuration("PT1S");
endDate.add(oneSecond);
} catch (DatatypeConfigurationException e) {
// do nothing
}
return appliedOutages;
}
示例9: getXMLCalendar
import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
/**
* <pre>
* 描述:日期轉XMLGregorianCalendar
* 作者:ZhangYi
* 時間:2016年5月5日 下午4:13:36
* 參數:(參數列表)
* @param date 日期
* @return
* </pre>
*/
public static XMLGregorianCalendar getXMLCalendar(Date date) {
DatatypeFactory datatypeFactory = null;
try {
datatypeFactory = DatatypeFactory.newInstance();
} catch (DatatypeConfigurationException e) {
logger.error("獲取時間轉換工廠時發生錯誤", e);
}
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(date);
XMLGregorianCalendar datetime = datatypeFactory.newXMLGregorianCalendar(calendar);
return datetime;
}
示例10: getCurrentDateTime
import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
private XMLGregorianCalendar getCurrentDateTime() {
GregorianCalendar gc = new GregorianCalendar();
DatatypeFactory dtf = null;
try {
dtf = DatatypeFactory.newInstance();
} catch (DatatypeConfigurationException ex) {
ex.printStackTrace();
}
return dtf.newXMLGregorianCalendar(gc);
}
示例11: getXMLCalendar
import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
/**
* <pre>
* 描述:日期轉XMLGregorianCalendar
* 作者:ZhangYi
* 時間:2016年5月5日 下午4:13:36
* 參數:(參數列表)
* @param date
* @return
* </pre>
*/
public static XMLGregorianCalendar getXMLCalendar(Date date) {
DatatypeFactory datatypeFactory = null;
try {
datatypeFactory = DatatypeFactory.newInstance();
} catch (DatatypeConfigurationException e) {
logger.error("獲取時間轉換工廠時發生錯誤", e);
}
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(date);
XMLGregorianCalendar datetime = datatypeFactory.newXMLGregorianCalendar(calendar);
return datetime;
}
示例12: createTestFile
import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
/**
* Create test files
*
* @param javaVersion JDK version
*/
public void createTestFile(String javaVersion) {
try {
DatatypeFactory dtf = DatatypeFactory.newInstance();
XMLGregorianCalendar c = dtf.newXMLGregorianCalendar(EXPECTED_CAL);
Duration d = dtf.newDuration(EXPECTED_DURATION);
toFile((Serializable) c, filePath + javaVersion + FILENAME_CAL);
toFile((Serializable) d, filePath + javaVersion + FILENAME_DURATION);
} catch (Exception e) {
fail(e.getMessage());
}
}
示例13: testToString
import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
@Test
public void testToString() {
try {
String inputDateTime = "2006-10-23T22:15:01.000000135+08:00";
DatatypeFactory factory = DatatypeFactory.newInstance();
XMLGregorianCalendar calendar = factory.newXMLGregorianCalendar(inputDateTime);
String toStr = calendar.toString();
Assert.assertTrue(toStr.indexOf("E") == -1, "String value cannot contain exponent");
} catch (DatatypeConfigurationException dce) {
dce.printStackTrace();
Assert.fail("Failed to create instance of DatatypeFactory " + dce.getMessage());
}
}
示例14: test
import javax.xml.datatype.DatatypeFactory; //導入方法依賴的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");
}
示例15: generateDemographicType
import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
public static DemographicsType generateDemographicType(String dob) throws DatatypeConfigurationException {
org.indivo.xml.phr.demographics.ObjectFactory dObjFactory = new org.indivo.xml.phr.demographics.ObjectFactory();
DemographicsType indiDemographic = dObjFactory.createDemographicsType();
DatatypeFactory dataTypeFactory = DatatypeFactory.newInstance();
Date dobDate = UtilDateUtilities.StringToDate(dob, "yyyy/MM/dd");
GregorianCalendar dobGregorian = new GregorianCalendar();
dobGregorian.setTime(dobDate);
XMLGregorianCalendar dobxml = dataTypeFactory.newXMLGregorianCalendar(dobGregorian);
indiDemographic.setDateOfBirth(dobxml);
return indiDemographic;
}