Last active
April 27, 2019 22:04
-
-
Save juanpabloprado/dedaafdcd34728acc66752c2bc9da663 to your computer and use it in GitHub Desktop.
Localized formatting for LocalTime on the Java Shell tool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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