Here you can find the source of dateToXml(Date date)
public static XMLGregorianCalendar dateToXml(Date date)
//package com.java2s; import java.util.Calendar; import java.util.Date; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; public class Main { public static XMLGregorianCalendar dateToXml(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);//w ww. j a va2 s .c o m XMLGregorianCalendar sdate = null; try { sdate = DatatypeFactory.newInstance().newXMLGregorianCalendar(); sdate.setYear(calendar.get(Calendar.YEAR)); sdate.setMonth(calendar.get(Calendar.MONTH) + 1); sdate.setDay(calendar.get(Calendar.DAY_OF_MONTH)); sdate.setHour(calendar.get(Calendar.HOUR_OF_DAY)); sdate.setMinute(calendar.get(Calendar.MINUTE)); sdate.setSecond(calendar.get(Calendar.SECOND)); sdate.setTimezone(calendar.get(Calendar.ZONE_OFFSET) / 60000); } catch (Exception e) { e.printStackTrace(); } return sdate; } }