Skip to content

Instantly share code, notes, and snippets.

@juanpabloprado
Last active April 27, 2019 22:04
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/dedaafdcd34728acc66752c2bc9da663 to your computer and use it in GitHub Desktop.
Save juanpabloprado/dedaafdcd34728acc66752c2bc9da663 to your computer and use it in GitHub Desktop.
Localized formatting for LocalTime on the Java Shell tool
jshell> // Passing Formatter to LocalTime format method
jshell> import java.time.LocalTime;
jshell> LocalTime lt = LocalTime.now();
lt ==> 16:48:31.159343
jshell> "SHORT: " + lt.format(DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT));
$77 ==> "SHORT: 4:48 PM"
jshell> "MEDIUM: " + lt.format(DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM));
$78 ==> "MEDIUM: 4:48:31 PM"
jshell> // Passing LocalTime instance to Formatter's format method
jshell> "SHORT: " + DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).format(lt);
$79 ==> "SHORT: 4:48 PM"
jshell> "MEDIUM: " + DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM).format(lt);
$80 ==> "MEDIUM: 4:48:31 PM"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment