Format LocalDateTime To Localized String (FormatStyle.MEDIUM)

May 16, 2018
val text = localDateTime.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM))

FormatStyle

  • FULL: Tuesday, April 12, 1952 AD or 3:30:42pm PST
  • LONG: January 12, 1952
  • MEDIUM: Jan 12, 1952
  • SHORT: 12.13.52 or 3:30pm

If your LocalDateTime is in UTC, you might want to convert it to local (system default) timezone before displaying the localized date string.

val localDateTime = uctLocalDateTime.atZone(ZoneOffset.UTC).withZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime()
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.