Update recommendations regarding ISO and concrete patterns

master
Sam Brannen 1 year ago
parent
commit
72a193cadd
  1. 10
      Date-and-Time-Formatting-with-JDK-20-and-higher.md

10
Date-and-Time-Formatting-with-JDK-20-and-higher.md

@ -24,19 +24,21 @@ Consequently, developers and frameworks must find a way to either avoid or deal @@ -24,19 +24,21 @@ Consequently, developers and frameworks must find a way to either avoid or deal
The Spring team recommends the use of ISO standardized formats for both parsing and formatting of date/time values whenever possible. For example, consider using a predefined `iso` pattern in Spring's `@DateTimeFormat` annotation (such as `ISO.DATE_TIME`) or one of the `ISO_*` constants defined in `java.time.format.DateTimeFormatter` (such as `ISO_DATE_TIME`) for programmatic handling of JSR-310 `java.time` value types.
If using an ISO standardized format is not an option for your use case, consider one of the _lenient_ approaches outlined below.
Another option is to always use date/time formatting patterns that you control. In other words, instead of relying on predefined locale-sensitive patterns such as `@DateTimeFormat(style = "-M")` or `java.time.format.FormatStyle.MEDIUM` to parse or format a time, define your own date/time pattern that parses and formats times the way you expect – for example, `"HH:mm a"` to handle US English times such as `3:30 PM`.
Using an ISO standardized format or a concrete pattern that you control allows for reliable system-independent and locale-independent parsing and formatting of date/time values. However, if that is not an option for your use case, consider one of the _lenient_ approaches outlined below.
The Spring team also recommends the use of UTF encoding whenever possible – for example, `UTF-8`.
### Lenient `@DateTimeFormat` Configuration
## Lenient Parsing in Application Code and Tests
TODO
### Lenient Parsing in Tests and Application Code
#### Lenient `@DateTimeFormat` Configuration
TODO
### Lenient `SimpleDateFormat` and `DateTimeFormatter` Configuration
#### Lenient `SimpleDateFormat` and `DateTimeFormatter` Configuration
In JDK 23, the Java team introduced support for lenient parsing of space characters in `SimpleDateFormat` as well as `DateTimeFormatter`.

Loading…
Cancel
Save