https://kotlinlang.org logo
#android
Title
# android
l

lawlorslaw

06/11/2019, 6:41 AM
what is the best practice around using dates in Kotlin. Should we avoid using the Java Date or Calendar classes? What is the replacement for this? Are there any good blog posts around this topic?
g

gildor

06/11/2019, 6:41 AM
There is no replacement
at least for now
m

Matej Drobnič

06/11/2019, 6:42 AM
I'm using https://github.com/JakeWharton/ThreeTenABP which is java.time backport with a bunch of tweaks for Android
☝️ 3
g

gildor

06/11/2019, 6:42 AM
Use java.time if you have it, if you don’t use Date
Yes, it’s the best choice if you target not only newest Androids and you heavily use date/calendar API
m

Matej Drobnič

06/11/2019, 6:43 AM
Date and Calendar are fine if you are only dealing with fixed points in time (e.g exact date and time in exact timezone), but once you stray away from that, it becomes a pain
1
For example, just displaying dates and time to the user, regardless of the timezone is a pain in Date/Calendar world