Skip to content Skip to sidebar Skip to footer

Droid Api 22+ Options For Date/duration (in Kotlin)?

I'm porting an iOS app to Android, target API 22. I do a bunch of Date/TimeInterval stuff. I do it all in UTC so it just works for me. I'm struggling with what to use for Android.

Solution 1:

Yes, there is a backport of the “Java 8 stuff”, also known as java.time or just the modern Java date and time API. The backport has even been adapted specifically for Android.

  • For non-Android Java 6 and 7 get the ThreeTen Backport, the backport of the new classes (ThreeTen for JSR 310; see the links at the bottom).
  • For Android API level 22 (and anything under 26) use the Android edition of ThreeTen Backport. It’s called ThreeTenABP. And make sure you import the date and time classes from org.threeten.bp with subpackages.

I am told that dependencies is:

compile group: 'org.threeten', name: 'threetenbp', version: '1.3.3', classifier: 'no-tzdb'

I am sorry that I haven’t got experience with ThreeTenABP myself. My experience with java.time suggests that it is just what you need. The backport was developed by the same folks that developed java.time, so I would immediately suppose that it’s as reliable as it gets. Only limitation seems to be that it is not getting upgraded with the (minor) new functionality added to java.time in Java 9 and later.

Links

Post a Comment for "Droid Api 22+ Options For Date/duration (in Kotlin)?"