From some generated code I get a
javax.xml.datatype.XMLGregorianCalendar
and I want to convert it to a LocalDateTime
without any zone-offset (UTC).
My current code accomplishes it, but I think it must be possible to acheaf the same result in a more elegant (and shorter) way.
public static LocalDateTime xmlGregorianCalendar2LocalDateTime(XMLGregorianCalendar xgc) {
// fix the time to UTC:
final int offsetSeconds = xgc.toGregorianCalendar().toZonedDateTime().getOffset().getTotalSeconds();
final LocalDateTime localDateTime = xgc.toGregorianCalendar().toZonedDateTime().toLocalDateTime(); // this simply ignores the timeZone
return localDateTime.minusSeconds(offsetSeconds); // ajust according to the time-zone offet
}