Java XML Transform Usage dateToGregorian(Date date)

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

Description

Transform a date in Date to XMLGregorianCalendar

License

Open Source License

Declaration

public static XMLGregorianCalendar dateToGregorian(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.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

public class Main {
    /**/*from  w  ww  .j a v a  2  s  .  c o  m*/
     * Transform a date in Date to XMLGregorianCalendar
     */
    public static XMLGregorianCalendar dateToGregorian(Date date) {
        return longToGregorian(date.getTime());
    }

    /**
     * Transform a date in a long to a GregorianCalendar
     * 
     * @param date
     * @return
     */
    public static XMLGregorianCalendar longToGregorian(long date) {
        DatatypeFactory dataTypeFactory;
        try {
            dataTypeFactory = DatatypeFactory.newInstance();
        } catch (DatatypeConfigurationException e) {
            throw new RuntimeException(e);
        }
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTimeInMillis(date);
        return dataTypeFactory.newXMLGregorianCalendar(gc);
    }
}

Related

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