Hey all, Does anyone here use the `NSDate(timeInte...
# multiplatform
i
Hey all, Does anyone here use the
NSDate(timeIntervalSince1970: ...)
initializer in Kotlin to create a date object from a timestamp in seconds? I'm working on iOS-specific code to return a formatted date string given a timestamp, but the available initializers seem limited. Specifically, I can only use
NSDate(timeIntervalSinceReferenceDate: ...)
or
NSDate()
. However, I need to work with
NSDate(timeIntervalSinceReferenceDate: ...)
for my implementation. What do you typically use to format dates across iOS and Android?
a
Use kotlinx.datetime lib?
👍 1
j
The best path would be to use LocalDate / LocalDateTime from kotlinx.datetime, i.e. if you were starting a new app from scratch
In my app, I see that in one place, to format a LocalDate to String on iOS, I used
toNSDateComponents()
, got an NSDate from that, and passed that to
stringFromDate
of an NSDateFormatter. This was in an expect/actual function.