Java tutorial
//package com.java2s; import java.sql.Timestamp; import java.util.Date; import java.util.GregorianCalendar; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; public class Main { private static DatatypeFactory newInstance; public static XMLGregorianCalendar toXMLGregorianCalendar(Date date) { if (date == null) return null; GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(date); return newInstance.newXMLGregorianCalendar(calendar); } public static XMLGregorianCalendar toXMLGregorianCalendar(String date) { if (date == null) return null; return newInstance.newXMLGregorianCalendar(date); } public static XMLGregorianCalendar toXMLGregorianCalendar(GregorianCalendar c) { if (c == null) return null; return newInstance.newXMLGregorianCalendar(c); } public static XMLGregorianCalendar toXMLGregorianCalendar(Timestamp t) { if (t == null) return null; GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(t); return newInstance.newXMLGregorianCalendar(calendar); } }