Wrangling Dates & Time in Android

Dec 15 2022 Kotlin 1.6.21, Android 13, IntelliJ 2022.1

Part 1: Wrangling Dates & Time in Android

9. Implement the Data-Time API in Android

Episode complete

Save for later
About this episode
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 8. Work the Kotlinx-Datetime API

This video Implement the Data-Time API in Android was last updated on Dec 15 2022

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.

Congrats! You’ve finished the course about the Java Date-Time library. But you still miss one piece of the puzzle, implementing it on Android. It might sound very easy to do so, but there’s something you need to know. Java Date-Time library comes out with Java 8. Android, however, natively supports Java 8 only since Android ******SDK 26, also known as Android Oreo. So how can we support version prior to the SDK 26. Well, fortunately, Google has released the Core Library Desugaring, which implements the new language features by performing bytecode transformations called desugar. If you reach minSDK 26 in the future you can simply remove the library desugaring to use the build-in Java 8 APIs.

// Required when setting minSdkVersion to 20 or lower
multiDexEnabled true
// Flag to enable support for the new language APIs
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.0'
val currentDate = remember {
  LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE)
}
Text(currentDate)