Java XML Date to getGmtTimeFromXMLGregorianCalendar( XMLGregorianCalendar xgcal)

Here you can find the source of getGmtTimeFromXMLGregorianCalendar( XMLGregorianCalendar xgcal)

Description

Returns a time string of the form yyyy-MM-dd'T'HH:mm:ss'Z' from the specified XMLGregorianCalendar.

License

Open Source License

Parameter

Parameter Description
xgcal a parameter

Declaration

public static String getGmtTimeFromXMLGregorianCalendar(
        XMLGregorianCalendar xgcal) 

Method Source Code

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

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;

import java.util.TimeZone;
import javax.xml.datatype.XMLGregorianCalendar;

public class Main {
    /** String used for non-available data */
    private static final String NOT_AVAILABLE = "NA";

    /**//from   www . j av  a2s  . co  m
     * Returns a time string of the form yyyy-MM-dd'T'HH:mm:ss'Z' from the
     * specified XMLGregorianCalendar. If the input is null, then the value of
     * NOT_AVAILABLE is returned.
     * 
     * @param xgcal
     * @return
     * @see #NOT_AVAILABLE
     */
    public static String getGmtTimeFromXMLGregorianCalendar(
            XMLGregorianCalendar xgcal) {
        if (xgcal == null) {
            return NOT_AVAILABLE;
        }
        GregorianCalendar gcal = xgcal.toGregorianCalendar(
                TimeZone.getTimeZone("GMT"), null, null);
        // Get the date
        Date date = gcal.getTime();
        SimpleDateFormat formatter = new SimpleDateFormat(
                "yyyy-MM-dd'T'HH:mm:ss'Z'");
        // Make a new local GregorianCalendar with this date
        gcal = new GregorianCalendar();
        gcal.setTime(date);
        formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
        return formatter.format(date);
    }
}

Related

  1. GetDateDiffInDays(XMLGregorianCalendar Calendar)
  2. getDateFromXmlGregorianCalendar(XMLGregorianCalendar da)
  3. getDateFromXMLGregorianCalendar(XMLGregorianCalendar xmlCalendar)
  4. getDateFromXMLGregorianCalendar(XMLGregorianCalendar xmlGregorianCalendar)
  5. getDurationFromCalendar( final XMLGregorianCalendar cal)
  6. getLocalTimeFromXMLGregorianCalendar( XMLGregorianCalendar xgcal)
  7. getMilliseconds(XMLGregorianCalendar xmlCalendar)
  8. getNextMonthDate(GregorianCalendar calendar)
  9. toTimestamp(XMLGregorianCalendar calendar)