Search code examples
javaandroidlocaldateandroid-api-levels

LocalDate alternative for API level 19 or lower?


I'm developing an app for managing appointments and had already made the entire backend with LocalDate and LocalTime. However, it happens these classes are only supported for API level 26 or higher, which is too high.

I know Date exists and will use it if I have to, but is there another (intermediate) option I could use that's supported for at least levels 18 or 19? Hopefully changing as little code as possible.


Solution

  • Never use the legacy date-time classes such as Date, Calendar, and SimpleDateFormat. They are terrible, designed by people who did not understand date-time handling.

    java.time

    Android 26 and later carries an implementation of JSR 310 in the java.time classes.

    ThreeTen-Backport

    Most of the java.time functionality is back-ported to Java 6 & Java 7 in the ThreeTen-Backport project.

    The API intentionally mimics that of java.time.

    ThreeTenABP

    Further adapted to early Android before 26 in the ThreeTenABP project.