Wrangling Dates & Time in Android

Dec 15 2022 Kotlin 1.6.21, Android 13, IntelliJ 2022.1

Part 1: Wrangling Dates & Time in Android

8. Work the Kotlinx-Datetime API

Episode complete

Play next episode

Next
Save for later
About this episode
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 7. Format Dates & Time With DataTimeFormatter Next episode: 9. Implement the Data-Time API in Android

Check the repository here.

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.

In the previous video, you learned all the essential concepts about the Java Date-Time library. But since you’re a Kotlin developer you need to know that the JetBrains, Kotlin’s mother, has also released its own Date-Time library written in Kotlin.

implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
val instant = Clock.System.now()
println("instant: $instant")
val tz = TimeZone.of("Europe/Rome")
val local = LocalDate(2022, Month.OCTOBER, 25)
    .atTime(2, 30)
val editedInstant = instant + 5.hours
println("editedInstant: $editedInstant")
val duration: Duration = instant - instant.minus(50, DateTimeUnit.HOUR)
println("duration: $duration")
val convertedIntoPeriod = duration.toDateTimePeriod()
println("days: $convertedIntoPeriod")