Java tutorial
//package com.java2s; import java.util.Calendar; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; public class Main { /** * date -> XMLGregorianCalendar * * @param date * @return XMLGregorianCalendar * @throws DatatypeConfigurationException */ @SuppressWarnings("static-access") public static XMLGregorianCalendar getXMLGregorianCalendar(java.util.Date date) throws DatatypeConfigurationException { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); 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)); } }