Java XML Date Create getXMLGregorianCalendarFromDate(Date date)

Here you can find the source of getXMLGregorianCalendarFromDate(Date date)

Description

Converts a Date into a XMLGregorianCalendar

License

Open Source License

Parameter

Parameter Description
date the date to be converted

Exception

Parameter Description
DatatypeConfigurationException an exception

Return

the XMLGregorianCalendar representing the date converted

Declaration

public static XMLGregorianCalendar getXMLGregorianCalendarFromDate(Date date)
        throws DatatypeConfigurationException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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 {
    /**//from  w w  w.  j a va2 s.  c o m
     * Converts a {@link Date} into a {@link XMLGregorianCalendar}
     * 
     * @param date
     *            the date to be converted
     * @return the XMLGregorianCalendar representing the date converted
     * @throws DatatypeConfigurationException
     */
    public static XMLGregorianCalendar getXMLGregorianCalendarFromDate(Date date)
            throws DatatypeConfigurationException {
        XMLGregorianCalendar retObj = null;

        if (date != null) {
            GregorianCalendar gregCal = new GregorianCalendar();
            gregCal.setTime(date);

            retObj = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregCal);
        }

        return retObj;
    }
}

Related

  1. getXMLGregorianCalendar(Date date)
  2. getXMLGregorianCalendar(Date date)
  3. getXmlGregorianCalendar(String unixTime)
  4. getXMLGregorianCalendar(TimeZone timeZone, Locale locale)
  5. getXMLGregorianCalendarFromDate(Date date)
  6. getXMLGregorianCalendarValue( Date date)
  7. getXMLGregorianCalenderDate()
  8. toDate(final XMLGregorianCalendar xml)
  9. toDate(long date)