Java tutorial
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; 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 { /** * Convert date from String to Xml GregorianCalendar in this 'MM/dd/yyyy hh:mm:ss' * @param s * @return * @throws DatatypeConfigurationException * @throws ParseException */ public static XMLGregorianCalendar stringToXMLGregorianCalendar(String s) throws DatatypeConfigurationException, ParseException { if (s != null && !(s.trim().length() < 1)) { XMLGregorianCalendar result = null; Date date; SimpleDateFormat simpleDateFormat; GregorianCalendar gregorianCalendar; simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss"); date = simpleDateFormat.parse(s); gregorianCalendar = (GregorianCalendar) GregorianCalendar.getInstance(); gregorianCalendar.setTime(date); result = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar); return result; } return null; } }