Java tutorial
//package com.java2s; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; import java.util.GregorianCalendar; public class Main { public static XMLGregorianCalendar parse(String time) { XMLGregorianCalendar date = null; try { if (time.indexOf(":") < 0) { time = time + "T00:00:00"; } date = DatatypeFactory.newInstance().newXMLGregorianCalendar(time); } catch (DatatypeConfigurationException e) { e.printStackTrace(); } return date; } public static XMLGregorianCalendar parse(String time, int timezone) { XMLGregorianCalendar date = null; try { if (time.indexOf(":") < 0) { time = time + "T00:00:00"; } date = DatatypeFactory.newInstance().newXMLGregorianCalendar(time); date.setTimezone(timezone); } catch (DatatypeConfigurationException e) { e.printStackTrace(); } return date; } public static XMLGregorianCalendar parse(long time) { return parse(time, 0); } public static XMLGregorianCalendar parse(long time, int timezone) { GregorianCalendar cal = new GregorianCalendar(); cal.setTimeInMillis(time); XMLGregorianCalendar xCal = null; try { xCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal); xCal.setTimezone(timezone); } catch (DatatypeConfigurationException e) { e.printStackTrace(); } return xCal; } }