Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert an Epoch to a OffsetDateTime in Kotlin?

The postgresql Timestamp with Time Zone data type needs to be supplied an OffsetDateTime when being called using a High level language like Kotlin. I could not find a direct method that supports Epoch to OffsetDateTime conversion.

like image 248
Raj Avatar asked Dec 23 '22 23:12

Raj


1 Answers

fun convertEpochToOffsetDateTime(epochValue: Long): OffsetDateTime {
  return OffsetDateTime.of(LocalDateTime.ofEpochSecond(epochValue, 0, ZoneOffset.UTC), ZoneOffset.UTC)
} 

Btw, I'm using Jooq for SQL queries using Kotlin. The above works like a charm.

like image 155
Raj Avatar answered Jan 14 '23 14:01

Raj