Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Date; import java.util.GregorianCalendar; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; public class Main { /** * Converts a {@link Date} into a {@link XMLGregorianCalendar} * * @param date * the date to be converted * @return the XMLGregorianCalendar representing the date converted * @throws DatatypeConfigurationException */ public static XMLGregorianCalendar getXMLGregorianCalendarFromDate(Date date) throws DatatypeConfigurationException { XMLGregorianCalendar retObj = null; if (date != null) { GregorianCalendar gregCal = new GregorianCalendar(); gregCal.setTime(date); retObj = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregCal); } return retObj; } }