1

Hello everyone i am just learning android and i got this case when i have the data with content of
2021-05-16T05:02:26Z
which have this format yyyy-MM-dd'T'HH:mm:ss
How can i convert it to Sunday-May-2021 05:02 ?
I've tried googling and exploring the web but most of them only convert yyyy-MM-dd'T'HH:mm:ss to dd-mm-yyyy and any other format, haven't found one that convert it to human readable.

Thanks in advance.

radren
  • 154
  • 2
  • 14
  • Don’t you want to have the day of the month in the format (16 in the example)? And don’t you want the time converted to the user’s time zone? The time in your string is in UTC (05:02 in the example). – Ole V.V. May 17 '21 at 14:40
  • 1
    Related, only based on Java instead of Kotlin: [Date formatting based on user locale on android](https://stackoverflow.com/questions/11093182/date-formatting-based-on-user-locale-on-android). – Ole V.V. May 17 '21 at 19:03

1 Answers1

3

Check out DateTimeFormatter patterns. In your case it would look like this:

import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter

val zonedTime = ZonedDateTime.parse("2021-05-16T05:02:26Z")
val formatted : String = zonedTime.format(DateTimeFormatter.ofPattern("EEEE-MMMM-u HH:mm"))
nluk
  • 684
  • 1
  • 7
  • 14