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

Next
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’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

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
    .ofLocalizedDate(FormatStyle.MEDIUM)
    .withLocale(Locale.FRANCE)
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")