Posted by Unknown on 2:55 PM

Below is the code conversion for XMLGregorianCalander to Date and Date to XMLGregorianCalander.

/**
* Convert java.util.Date into XMLGregorianCalendar object.
* @param date Date Object.
* @return XMLGregorianCalendar Object.
* @see XMLGregorianCalendar XMLGregorianCalendar.
*/
public static XMLGregorianCalendar toXMLGregorianCalendar(final Date aDtDate) {
XMLGregorianCalendar mVReturnCal = null;
try {
final GregorianCalendar mVCalendar = new GregorianCalendar();
mVCalendar.setTime(aDtDate);
mVReturnCal = DatatypeFactory.newInstance()
.newXMLGregorianCalendar(mVCalendar);
} catch (DatatypeConfigurationException ex) {
APPLICATION_LOG.error("Exception is=>",ex);
}
return mVReturnCal;
}
/**
* Convert java.util.Date into XMLGregorianCalendar object. Time Format.
* @param date Date Object.
* @return XMLGregorianCalendar Object.
* @see XMLGregorianCalendar XMLGregorianCalendar.
*/
public static XMLGregorianCalendar toXMLGregorianCalendarTime(final Date aDtDate) {
XMLGregorianCalendar mVReturnCal = null;
try {
final XMLGregorianCalendar mvTempCal = toXMLGregorianCalendar(aDtDate);
mVReturnCal = DatatypeFactory.newInstance()
.newXMLGregorianCalendarTime(
mvTempCal.getHour(),
mvTempCal.getMinute(),
mvTempCal.getSecond(),
mvTempCal.getTimezone());
} catch (DatatypeConfigurationException ex) {
APPLICATION_LOG.error("Exception is=>",ex);
}
return mVReturnCal;
}
/**
* Convert XMLGregorianCalendar to java.util.Date object.
* @param mVXMLCal XMLGregorianCalendar Object
* @return Date Object
* @see XMLGregorianCalendar
*/
public static java.util.Date toDate(final XMLGregorianCalendar mVXMLCal) {
java.util.Date mDtDate = null;
try {
final GregorianCalendar mVGregCalendar =
mVXMLCal.toGregorianCalendar();
mDtDate = mVGregCalendar.getTime();
} catch (Exception ex) {
APPLICATION_LOG.error("Exception is=>",ex);
}
return mDtDate;
}

0 comments: