Java XML Date Create toXmlDateTimeUTC(Date date)

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

Description

Returns a XMLGregorianCalender (xml:dateTime) in UTC

License

Open Source License

Parameter

Parameter Description
date the date to convert

Return

dateTime in UTC e.g. 2012-03-14T12:34:56.789Z

Declaration

public static XMLGregorianCalendar toXmlDateTimeUTC(Date date) 

Method Source Code

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

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

import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public class Main {
    private static DatatypeFactory factory = null;
    private static final TimeZone UTC = TimeZone.getTimeZone("UTC");

    /**//from   w  w w.  j av  a  2  s  . com
     * Returns a XMLGregorianCalender (xml:dateTime) in UTC
     *
     * @param date the date to convert
     * @return dateTime in UTC e.g. 2012-03-14T12:34:56.789Z
     */
    public static XMLGregorianCalendar toXmlDateTimeUTC(Date date) {
        if (date != null) {
            GregorianCalendar cal = new GregorianCalendar(UTC);
            cal.setTime(date);
            return factory.newXMLGregorianCalendar(cal);
        } else {
            return null;
        }
    }
}

Related

  1. toXMLDate(Date date)
  2. toXmlDate(Date date)
  3. toXmlDate(DateTime cal)
  4. toXmlDate(GregorianCalendar date)
  5. toXmlDateTime(GregorianCalendar cal)
  6. toXMLGregorianCalendar(Date date)
  7. toXMLGregorianCalendar(Date date)
  8. toXMLGregorianCalendar(Date date, TimeZone timeZone, Locale locale)
  9. toXmlGregorianCalendar(GregorianCalendar calendar)