Skip to content
Advertisement

ZonedDateTime to Date before Java 8 in early Android

I am trying to replace the ZonedDateTime.toInstant method because it is only available since API 26 for Android.
But my app is supposed to support API 19.
I want to convert the ZonedDateTime to a Date so i can do something like this:

JavaScript

What i want to achieve is the following:
I want to calculate the difference between the current date and another date in Seconds, Minutes, Hours, … the highest possible unit wins, so i would get e.g. 5 days ago as result.

Advertisement

Answer

Solution (ThreeTen-Backport Library):
It’s working perfectly, i already tried it out on an KitKat emulator.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement