What's the best way to convert between LocalDate
from Java 8 and XMLGregorianCalendar
?
Converting from LocalDate
to XMLGregorianCalendar
:
LocalDate date = LocalDate.now();
GregorianCalendar gcal = GregorianCalendar.from(date.atStartOfDay(ZoneId.systemDefault()));
XMLGregorianCalendar xcal = DatatypeFactory.newInstance().newXMLGregorianCalendar(gcal);
Converting back is simpler:
xcal.toGregorianCalendar().toZonedDateTime().toLocalDate();