Java XML Date Create createXMLGregorianCalendar(Date currentDateTime)

Here you can find the source of createXMLGregorianCalendar(Date currentDateTime)

Description

create XML Gregorian Calendar

License

Open Source License

Declaration

public static XMLGregorianCalendar createXMLGregorianCalendar(Date currentDateTime) 

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.DatatypeConstants;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

public class Main {
    public static XMLGregorianCalendar createXMLGregorianCalendar(Date currentDateTime) {
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(currentDateTime);

        XMLGregorianCalendar createDate;
        try {//from  w  w  w .j  a va2  s.  com
            createDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);
            createDate.setMillisecond(DatatypeConstants.FIELD_UNDEFINED);
            createDate.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
        } catch (DatatypeConfigurationException e) {
            throw new RuntimeException(e);
        }

        return createDate;
    }
}

Related

  1. createXmlGregorianCalendar(Date date)
  2. createXMLGregorianCalendar(final Date date)
  3. createXMLGregorianCalendar(final Date time)
  4. dateToString(Calendar calendar)