Here you can find the source of toXMLGregorianCalendar(Date date, TimeZone timeZone, Locale locale)
public static XMLGregorianCalendar toXMLGregorianCalendar(Date date, TimeZone timeZone, Locale locale) throws DatatypeConfigurationException
//package com.java2s; /*!/*from ww w.j a va 2s . c om*/ * mifmi-commons4j * https://github.com/mifmi/mifmi-commons4j * * Copyright (c) 2015 mifmi.org and other contributors * Released under the MIT license * https://opensource.org/licenses/MIT */ import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; public class Main { public static XMLGregorianCalendar toXMLGregorianCalendar(Date date) throws DatatypeConfigurationException { return toXMLGregorianCalendar(date, null, null); } public static XMLGregorianCalendar toXMLGregorianCalendar(Date date, TimeZone timeZone, Locale locale) throws DatatypeConfigurationException { if (date == null) { return null; } return toXMLGregorianCalendar(date.getTime(), timeZone, locale); } public static XMLGregorianCalendar toXMLGregorianCalendar(long date) throws DatatypeConfigurationException { return toXMLGregorianCalendar(date, null, null); } public static XMLGregorianCalendar toXMLGregorianCalendar(long date, TimeZone timeZone, Locale locale) throws DatatypeConfigurationException { return DatatypeFactory.newInstance().newXMLGregorianCalendar(toGregorianCalendar(date, timeZone, locale)); } public static GregorianCalendar toGregorianCalendar(Date date) { return toGregorianCalendar(date, null, null); } public static GregorianCalendar toGregorianCalendar(Date date, TimeZone timeZone, Locale locale) { if (date == null) { return null; } return toGregorianCalendar(date.getTime(), timeZone, locale); } public static GregorianCalendar toGregorianCalendar(long date) { return toGregorianCalendar(date, null, null); } public static GregorianCalendar toGregorianCalendar(long date, TimeZone timeZone, Locale locale) { GregorianCalendar gccal = getGregorianCalendar(timeZone, locale); gccal.setTimeInMillis(date); return gccal; } public static GregorianCalendar getGregorianCalendar(TimeZone timeZone, Locale locale) { GregorianCalendar gcal; if (timeZone == null) { if (locale == null) { gcal = new GregorianCalendar(); } else { gcal = new GregorianCalendar(locale); } } else { if (locale == null) { gcal = new GregorianCalendar(timeZone); } else { gcal = new GregorianCalendar(timeZone, locale); } } return gcal; } }