How can I parse a Unix timestamp to a date string in Kotlin?
For example 1532358895
to 2018-07-23T15:14:55Z
How can I parse a Unix timestamp to a date string in Kotlin?
For example 1532358895
to 2018-07-23T15:14:55Z
The following should work. It's just using the Java libraries for handling this:
val sdf = java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
val date = java.util.Date(1532358895 * 1000)
sdf.format(date)
Or with the new Time API:
java.time.format.DateTimeFormatter.ISO_INSTANT
.format(java.time.Instant.ofEpochSecond(1532358895))