當前位置: 首頁>>代碼示例>>Java>>正文


Java DatatypeFactory.newXMLGregorianCalendar方法代碼示例

本文整理匯總了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;
}
 
開發者ID:Discovery-Research-Network-SCCM,項目名稱:FHIR-CQL-ODM-service,代碼行數:9,代碼來源:FhirService.java

示例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;
    }
}
 
開發者ID:autumnkuang,項目名稱:nenlvse1.0,代碼行數:19,代碼來源:DateUtil.java

示例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;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:16,代碼來源:GregorianCalendars.java

示例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());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:CalendarDuration1243Test.java

示例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());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:CalendarDuration1097Test.java

示例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;
}
 
開發者ID:ONSdigital,項目名稱:rm-common-service,代碼行數:22,代碼來源:DateTimeUtil.java

示例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;
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:29,代碼來源:XMLTools.java

示例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;
}
 
開發者ID:OmniPrise,項目名稱:cim-processor,代碼行數:15,代碼來源:ModelParser.java

示例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;
}
 
開發者ID:dev-share,項目名稱:css-elasticsearch,代碼行數:23,代碼來源:DateUtil.java

示例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);
}
 
開發者ID:dotwebstack,項目名稱:dotwebstack-framework,代碼行數:11,代碼來源:Rdf4jValueBackendTest.java

示例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;
}
 
開發者ID:dev-share,項目名稱:database-transform-tool,代碼行數:23,代碼來源:DateUtil.java

示例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());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:SerializationTest.java

示例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());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:XMLGregorianCalendarTest.java

示例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");

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:Bug6937951Test.java

示例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;
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:14,代碼來源:IndivoUtil.java


注:本文中的javax.xml.datatype.DatatypeFactory.newXMLGregorianCalendar方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。