Here you can find the source of transformStringToXMLGregorianCalendar(String dateTime, String pattern)
public static XMLGregorianCalendar transformStringToXMLGregorianCalendar(String dateTime, String pattern)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; public class Main { public static XMLGregorianCalendar transformStringToXMLGregorianCalendar(String dateTime, String pattern) { XMLGregorianCalendar xmlGregorianCalendar; SimpleDateFormat format = new SimpleDateFormat(pattern); try {//from ww w . j a v a 2 s .c o m xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(); Calendar calendar = Calendar.getInstance(); calendar.setLenient(true); calendar.setTime(format.parse(dateTime)); xmlGregorianCalendar.setYear(calendar.get(Calendar.YEAR)); xmlGregorianCalendar.setMonth(calendar.get(Calendar.MONTH) + 1); xmlGregorianCalendar.setDay(calendar.get(Calendar.DAY_OF_MONTH)); xmlGregorianCalendar.setHour(calendar.get(Calendar.HOUR_OF_DAY)); xmlGregorianCalendar.setMinute(calendar.get(Calendar.MINUTE)); xmlGregorianCalendar.setSecond(calendar.get(Calendar.SECOND)); // xmlGregorianCalendar.setMillisecond(calendar.get(Calendar.MILLISECOND)); return xmlGregorianCalendar; } catch (DatatypeConfigurationException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } return null; } }