Date – OffsetDateTime

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 LocalDateTimeSecond, 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())));
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.29.119