Convert java.sql.Timestamp to java.time.OffsetDateTime

Hard to believe but I think this is the simplest you can manage:

long millisSinceEpoch = timestamp.getTime();
Instant instant = Instant.ofEpochMilli(millisSinceEpoch)
OffsetDateTime dt = OffsetDateTime.ofInstant(instant, ZoneId.of("UTC"))

Yikes.

Leave a Reply

Your email address will not be published.