Wrangling Dates & Time in Android

Dec 15 2022 Kotlin 1.6.21, Android 13, IntelliJ 2022.1

Part 1: Wrangling Dates & Time in Android

6. Choose Between ZonedDateTime & Instant

Episode complete

Play next episode

Next
Save for later
About this episode
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 5. Localize With ZonedDateTime Next episode: 7. Format Dates & Time With DataTimeFormatter

This video Choose Between ZonedDateTime & Instant 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.

At this point, you might wonder: what’s the difference between Instant and ZonedDateTime?

val romeZone = ZonedDateTime.of(
    LocalDateTime.of(2022, 3, 26, 10, 0, 0),
    ZoneId.of("Europe/Rome")
  )
println(romeZone)
val instant1 = romeZone.plus(1, ChronoUnit.DAYS).toInstant()
val instant2 = romeZone.toInstant().plus(1, ChronoUnit.DAYS)
println(instant1)
println(instant2)
val zone1 = romeZone.plus(1, ChronoUnit.DAYS)
println(zone1)
val currentInstant = Instant.now()
val ztdFromInstant = currentInstant.atZone(ZoneId.systemDefault())
println("ztdFromInstant: $ztdFromInstant")