Format LocalDateTime To Localized String (FormatStyle.MEDIUM)

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

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

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.