I fail to understand how DecimalStyle influences my formatting/parsing with DateTimeFormatter. If I try:
date = LocalDateTime.now();
DecimalStyle ds = DecimalStyle.of(Locale.GERMAN);
formatter = DateTimeFormatter.ofPattern("yyyy").withDecimalStyle(ds.withDecimalSeparator('?'));
text = formatter.format(date);
System.out.println("DecimalStyle: " + text);
Shouldn't I get something like: 2.016 in my Output?
What I actually see is that whatever parameters I set to my ds
, it will never influence the actual formatted String.
This is java 8 API, so there's not much to find on the Internet, unfortunately.
The DecimalStyle
affects how 0
(zero), +
(positive), -
(negative) and .
(decimal separator) characters are represented. There is no decimal character in 2016
(there could be a thousand separator but DecimalStyle does not handle that).
An example that shows a difference:
LocalDateTime date = LocalDateTime.now();
DecimalStyle ds = DecimalStyle.of(Locale.GERMAN);
DateTimeFormatter noDs = DateTimeFormatter.ISO_LOCAL_TIME;
DateTimeFormatter withDs = DateTimeFormatter.ISO_LOCAL_TIME.withDecimalStyle(ds);
System.out.println("Default: " + noDs.format(date)); // Default: 17:44:54.457
System.out.println("German: " + withDs.format(date)); // German: 17:44:54,457
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With