How to convert to different date data types using XMLGregorianCalendar in Java
/**
* Returns XMLGregorianCalendar for Current Date and Time.
*/
public XMLGregorianCalendar getCurrentDateTimeAsXMLGregorianCalendar()
{
GregorianCalendar gc = new GregorianCalendar();
return new XMLGregorianCalendarImpl(gc);
}
/**
* Convert supplied XMLGregorianCalendar to java util Date
*/
public Date getJavaDateFromXMLGregorianCal(XMLGregorianCalendar pXCal)
{
if (pXCal != null)
{
return pXCal.toGregorianCalendar().getTime();
}
return null;
}
// Convert java.util.Date to XMLGregorianCalendar
public XMLGregorianCalendar toXMLGregorianCalendar(Date pDate)
{
GregorianCalendar gc = new GregorianCalendar();
gc.setTimeInMillis(pDate.getTime());
return new XMLGregorianCalendarImpl(gc);
}
/**
* Returns XMLGregorianCalendar for Current Date and Time.
*/
public XMLGregorianCalendar getCurrentDateTimeAsXMLGregorianCalendar()
{
GregorianCalendar gc = new GregorianCalendar();
return new XMLGregorianCalendarImpl(gc);
}
/**
* Convert supplied XMLGregorianCalendar to java util Date
*/
public Date getJavaDateFromXMLGregorianCal(XMLGregorianCalendar pXCal)
{
if (pXCal != null)
{
return pXCal.toGregorianCalendar().getTime();
}
return null;
}
// Convert java.util.Date to XMLGregorianCalendar
public XMLGregorianCalendar toXMLGregorianCalendar(Date pDate)
{
GregorianCalendar gc = new GregorianCalendar();
gc.setTimeInMillis(pDate.getTime());
return new XMLGregorianCalendarImpl(gc);
}