Here you can find the source of dateToGregorian(Date date)
public static XMLGregorianCalendar dateToGregorian(Date date)
//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 { /**/*from w ww .j a v a 2 s . c o m*/ * Transform a date in Date to XMLGregorianCalendar */ public static XMLGregorianCalendar dateToGregorian(Date date) { return longToGregorian(date.getTime()); } /** * Transform a date in a long to a GregorianCalendar * * @param date * @return */ public static XMLGregorianCalendar longToGregorian(long date) { DatatypeFactory dataTypeFactory; try { dataTypeFactory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(date); return dataTypeFactory.newXMLGregorianCalendar(gc); } }