Wrangling Dates & Time in Android

Dec 15 2022 · Kotlin 1.6.21, Android 13, IntelliJ 2022.1

Part 1: Wrangling Dates & Time in Android

06. Choose Between ZonedDateTime & Instant

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 05. Localize With ZonedDateTime Next episode: 07. Format Dates & Time With DataTimeFormatter

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

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")