What is the Android equivalent of java.time.Duration?
I need to use the class java.time.Duration
to represent the time interval from submicroseconds to seconds. However, Android Studio does not provide this option.
I
guess I could use float
and express everything as seconds, but that doesn’t seem very intuitive and makes sense.
These intervals have nothing to do with any real-world timeline, they are just spacers.
Solution
Rear port
See also back-port of much of java.time through Java 6 and 7, and it adaptation for Android.
Backward ports include org.threeten.bp.Duration
Kind.
About java.time
placed in Java 8 and later within the java.time framework. These classes replace the troublesome old classes legacy datetime classes, eg java.util.Date
, Calendar
, & SimpleDateFormat
.
Joda-Time project, now in maintenance mode, it is recommended to migrate to java.time class.
To learn more, see Oracle Tutorial. The specification is JSR 310
Where do I get the java.time class?
- Java SE 8 and SE 9 then
- Built.
- Part of a standard Java API with a bundle implementation.
- Java 9 adds some minor features and fixes.
- Java SE 6 and SE 7
- Many java.time features are backported to Java 6 and 7 in ThreeTen-Backport
- Android
- ThreeTenABP project is adapted specifically for Android ThreeTen-Backport (as described above).
- See also > How to use ThreeTenABP….