Wrangling Dates & Time in Android

Dec 15 2022 Kotlin 1.6.21, Android 13, IntelliJ 2022.1

Part 1: Wrangling Dates & Time in Android

7. Format Dates & Time With DataTimeFormatter

Episode complete

Play next episode

Save for later
About this episode
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 6. Choose Between ZonedDateTime & Instant Next episode: 8. Work the Kotlinx-Datetime API

This video Format Dates & Time With DataTimeFormatter 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.

Until now, we’ve learned to work with date-time library classes. You know when you should use each class and how to use it. Now it’s time to work on the appearance and localization of your dates.

val date = "1902-07-22"
val localDate = LocalDate.parse(date, DateTimeFormatter.ISO_LOCAL_DATE)
println("LocalDate: $localDate")
val currentData1 = DateTimeFormatter.ISO_LOCAL_DATE.format(LocalDate.now())
println("currentData1: $currentData1")
val currentData2 = LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE)
println("currentData2: $currentData2")
val localizedDtf = DateTimeFormatter
val localizedDtfFormatted = localizedDtf.format(LocalDate.now())
println("localizedDtfFormatted: $localizedDtfFormatted")
val customDtf = DateTimeFormatter.ofPattern("MMM/dd/yy hh:mm a")
val customFormattedDate = customDtf.format(LocalDateTime.now())
println("customFormattedDate: $customFormattedDate")