Here you can find the source of createXmlGregorianCalendar(Date date)
public static XMLGregorianCalendar createXmlGregorianCalendar(Date date)
//package com.java2s; /*/*from ww w .j ava 2 s . co m*/ * eID PKI RA Project. * Copyright (C) 2010-2014 FedICT. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version * 3.0 as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, see * http://www.gnu.org/licenses/. */ import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; public class Main { private static DatatypeFactory datatypeFactory; /** * Converts the data to an XMLGregorianCalendar in the GMT time zone. */ public static XMLGregorianCalendar createXmlGregorianCalendar(Date date) { if (date == null) { return null; } GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(date); calendar.setTimeZone(TimeZone.getTimeZone("GMT")); return getDatatypeFactory().newXMLGregorianCalendar(calendar); } /** * Returns the data type factory to create exotic XML objects.. */ public synchronized static DatatypeFactory getDatatypeFactory() { if (datatypeFactory != null) { return datatypeFactory; } try { datatypeFactory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new RuntimeException("Cannot get DatatypeFactory", e); } return datatypeFactory; } }