Format LocalDateTime To String

Apr 20, 2018
// Sample output: 20180420-121341LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd-kkmmss"))

Check for format pattern

You can also used pre-defined DateTimeFormatter

  • ISO_LOCAL_DATE_TIME: e.g. 2011-12-03T10:15:30.111222
  • BASIC_ISO_DATE: e.g. 20111203
  • ISO_LOCAL_DATE: e.g. 2011-12-03
  • ISO_LOCAL_TIME: e.g. 10:15:30
  • ISO_OFFSET_DATE_TIME: e.g. 2011-12-03T10:15:30+01:00
  • RFC_1123_DATE_TIME: e.g. Tue, 3 Jun 2008 11:05:30 GMT
// Sample output: 2018-04-10T03:34:18.115LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)

❤️ 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.