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
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 5. Localize With ZonedDateTime Next episode: 7. Format Dates & Time With DataTimeFormatter

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

Take your career further with a Kodeco Pro subscription. 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.

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.

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