Wrangling Dates & Time in Android

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

Part 1: Wrangling Dates & Time in Android

07. Format Dates & Time With DataTimeFormatter

Episode complete

Play next episode

About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 06. Choose Between ZonedDateTime & Instant Next episode: 08. Work the Kotlinx-Datetime API

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've reached locked video content where the transcript will be shown as obfuscated text.

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