If one is trying to do a new "all kotlin/compose" ...
# getting-started
t
If one is trying to do a new "all kotlin/compose" app in Android, and needs to work with both instants in time as well as durations, is there an all-in-kotlin counterpart to java.time.Instant/Duration? I've been playing with a mixture of java.time.Instant and kotlin.time.Duration, but this feels like the two aren't well harmonized to each other. I see that there's a kotlinx-datetime.Instant, but not entirely clear what that is?
c
kotlinx-datetime is more-or-less a typealias over the java.time APIs. There are some slight differences, and I don’t know off the top of my head if it’s a proper typealias or a reimplementation, but it’s generally the same set of APIs and features. So whatever you’ve been using from the java.time package almost certainly can be done in a similar way with kotlinx-datetime, with the exception of parsing/formatting dates (though JB is looking into this)
s
The big difference is that ZonedDateTime is not present in DateTime, so you need to use Instant. Not sure if it's an issue for you, but depends on context