Converting from Date to OffsetDateTime relies on the toOffsetDateTime() method:
// e.g., 2019-03-01T07:25:25.624+02:00
public static OffsetDateTime dateToOffsetDateTime(Date date) {
return dateToInstant(date).atZone(
DEFAULT_TIME_ZONE).toOffsetDateTime();
}
An approach for converting from OffsetDateTime to Date requires two steps. First, convert OffsetDateTime to LocalDateTime. Second, convert LocalDateTime to Instant with the corresponding offset:
// e.g., Fri Mar 01 07:55:49 EET 2019
public static Date offsetDateTimeToDate(
OffsetDateTime offsetDateTime) {
return Date.from(offsetDateTime.toLocalDateTime()
.toInstant(ZoneOffset.of(offsetDateTime.getOffset().getId())));
}