Java XML Transform Usage DateToXML(Date date)

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

Description

Date To XML

License

Open Source License

Declaration

public static XMLGregorianCalendar DateToXML(Date date) 

Method Source Code

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

import java.util.Date;
import java.util.GregorianCalendar;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

public class Main {

    public static XMLGregorianCalendar DateToXML(Date date) {
        GregorianCalendar c = new GregorianCalendar();
        c.setTime(date);//from  w w  w  .j  a va2s .c om
        XMLGregorianCalendar xmlDate = null;
        try {
            xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
        } catch (Exception e) {
            // TODO: handle exception
            try {
                c.setTime(new Date());
                xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
            } catch (Exception e2) {
                // TODO: handle exception
            }
            System.out.println("Error al transformar fecha XML");
        }

        return xmlDate;
    }
}

Related

  1. createStaxResult(XMLStreamWriter streamWriter)
  2. createStaxSource(XMLStreamReader streamReader)
  3. createStreamResult(File outFile)
  4. createUnixStreamResultForEntry(OutputStream outputEntry)
  5. dateToGregorian(Date date)
  6. dumpMetadata(IIOMetadata meta)
  7. dumpMetadataToSystemOut(IIOMetadata iiometa)
  8. encodeBase64(Element elm)
  9. getCalendarAsXsdDateTime(Calendar c)