`kotlinx.datetime` provides a default serializer f...
# serialization
v
kotlinx.datetime
provides a default serializer for
kotlinx.datetime.LocalDateTime
which can only parse an ISO string like
"2023-02-20T22:07:12.668"
. Unfortunately, JavaScript/TypeScript's
Date().toISOString()
produces a string like
"2023-02-20T22:07:12.668Z"
- with the extra Z at the end. Do I need to change all my
LocalDateTime
to
Instant
? Or write my own serializer? Seems a little bit of unnecessary work ­čś× Or should I just hack it and chop off the 'Z' before posting my Json from the front end?
c
Instant and LocalDateTime are very different things, and you should be very careful not to mix them... JavaScript's
Date
class is an
Instant
.
v
I thought that might be the case. Is there a consensus on the right approach? I don't do much web development any more.
c
Well it depends what you want. If you want a local date time, use
LocalDateTime
on the Kotlin side, and do not use
Date
on the JS side. If you want a UTC date time, use
Instant
on the Kotlin side and
Date
on the JS side.
v
I am over thinking it. These are timestamps, so Long will be sufficient, or Instant.
c
Use Instant, then ­čÖé
102 Views