Java Utililty Methods XML Date to

List of utility methods to do XML Date to

Description

The list of methods to do XML Date to are organized into topic(s).

Method

DurationgetDurationFromCalendar(final XMLGregorianCalendar cal)

getDurationFromCalendar.

Duration dur;
try {
    dur = DatatypeFactory.newInstance().newDurationDayTime(cal.getTimezone() * 60000);
} catch (final DatatypeConfigurationException e) {
    return null;
return dur;
StringgetGmtTimeFromXMLGregorianCalendar(XMLGregorianCalendar xgcal)
Returns a time string of the form yyyy-MM-dd'T'HH:mm:ss'Z' from the specified XMLGregorianCalendar.
if (xgcal == null) {
    return NOT_AVAILABLE;
GregorianCalendar gcal = xgcal.toGregorianCalendar(TimeZone.getTimeZone("GMT"), null, null);
Date date = gcal.getTime();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
gcal = new GregorianCalendar();
gcal.setTime(date);
...
StringgetLocalTimeFromXMLGregorianCalendar(XMLGregorianCalendar xgcal)
Returns a time string of the form given by Date.toString() from the specified XMLGregorianCalendar.
if (xgcal == null) {
    return NOT_AVAILABLE;
GregorianCalendar gcal = xgcal.toGregorianCalendar(TimeZone.getTimeZone("GMT"), null, null);
Date date = gcal.getTime();
return date.toString();
longgetMilliseconds(XMLGregorianCalendar xmlCalendar)
get Milliseconds
return xmlCalendar.toGregorianCalendar().getTimeInMillis();
XMLGregorianCalendargetNextMonthDate(GregorianCalendar calendar)
get Next Month Date
DatatypeFactory df = DatatypeFactory.newInstance();
GregorianCalendar aCal = (GregorianCalendar) calendar.clone();
aCal.add(Calendar.MONTH, 1);
return df.newXMLGregorianCalendar(aCal);
TimestamptoTimestamp(XMLGregorianCalendar calendar)
to Timestamp
Timestamp result = new Timestamp(calendar.toGregorianCalendar().getTimeInMillis());
if (calendar.getFractionalSecond() != null)
    result.setNanos(calendar.getFractionalSecond().multiply(new BigDecimal(1000000000)).intValue());
return result;
longtoTimestamp(XMLGregorianCalendar xgc)
to Timestamp
return xgc.toGregorianCalendar().getTimeInMillis();
TimestamptoTimestamp(XMLGregorianCalendar xmlDate)
to Timestamp
if (xmlDate == null)
    return null;
return new Timestamp(xmlDate.toGregorianCalendar().getTime().getTime());