I'm trying to convert `java.time.LocalDateTime` to...
# announcements
s
I'm trying to convert
java.time.LocalDateTime
to
org.joda.time.DateTime
and back, so far I have created this extensions which seem to work fine:
Copy code
fun java.time.LocalDateTime.toJoda(): org.joda.time.DateTime = DateTime(this.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli())
fun org.joda.time.DateTime.toJava(): java.time.LocalDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(this.millis), ZoneId.systemDefault())
The LocalDateTime is used by JavaFX's DatePicker, and the DateTime is used by Exposed. Any comments or suggestions?
a
there’s some mismatch since LocalDateTime doesn’t really correspond to DateTime - if you’re ok with the assumption of “same instant in the local timezone”, this is fine, but you should be aware it’s a bit wonky
it’s likely that you are expecting to have the user pick a date in their local timezone, so it seems reasonable here
👍 1