Skip to content

Instantly share code, notes, and snippets.

@juanpabloprado
Last active April 27, 2019 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanpabloprado/17f643a78ed3f7121b2b837de28b063d to your computer and use it in GitHub Desktop.
Save juanpabloprado/17f643a78ed3f7121b2b837de28b063d to your computer and use it in GitHub Desktop.
Localized formatting for LocalDateTime on the Java Shell tool
jshell> // Passing Formatters to LocalDateTime format method
jshell> LocalDateTime ldt = LocalDateTime.now();
ldt ==> 2019-04-27T16:53:28.272418
jshell> ldt.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT));
$82 ==> "4/27/19, 4:53 PM"
jshell> ldt.format(DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT));
$83 ==> "4:53 PM"
jshell> ldt.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT));
$84 ==> "4/27/19"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment