Converts java.util.GregorianCalendar into javax.xml.datatype.XMLGregorianCalendar - Java XML

Java examples for XML:XML Calendar

Description

Converts java.util.GregorianCalendar into javax.xml.datatype.XMLGregorianCalendar

Demo Code


//package com.java2s;
import javax.xml.datatype.DatatypeConfigurationException;

import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

import java.util.GregorianCalendar;

public class Main {
    /**/*from  w w w  .java  2s.  c  o m*/
     * Converts java.util.GregorianCalendar into
     * javax.xml.datatype.XMLGregorianCalendar
     *
     * @param calendar
     *            the calendar
     * @return instance of XMLGregorianCalendar
     */
    public static XMLGregorianCalendar convert2XmlCalendar(
            GregorianCalendar calendar) {
        if (calendar == null) {
            return null;
        }

        try {
            return DatatypeFactory.newInstance().newXMLGregorianCalendar(
                    calendar);
        } catch (DatatypeConfigurationException e) {
            throw new RuntimeException(e);
        }
    }
}

Related Tutorials