Code example for XMLGregorianCalendar

Methods: toGregorianCalendar

0
public class ConversionUtils { 
	 
	private static Log logger = LogFactory.getLog(ConversionUtils.class);
 
	public static Date xmlGregorianCalendarToDate(XMLGregorianCalendar calendar) {
		return calendar.toGregorianCalendar().getTime();
	} 
	 
	public static XMLGregorianCalendar dateToXmlGregorianCalendar(Date date) {
		GregorianCalendar gc = new GregorianCalendar();
		gc.setTime(date);
		XMLGregorianCalendar xgc = null;
		 
		try { 
			xgc = DatatypeFactory.newInstance().newXMLGregorianCalendar(gc);
		 
		} catch (DatatypeConfigurationException dce) {
			logger.error("Error converting date to XmlGregorianCalendar: " + dce.getMessage());
		} 
		return xgc;
	}