我有一些text
仅在解析样式为DateTimeFormatter
时由Strict
解析,而不是在Lenient
解析时。
这似乎与我期望的行为相反?
示例:
String pattern = "ddMMyyHH:mm:ss";
String text = "02011104:21:32";
System.out.println(MessageFormat.format("Strict - {0}", new DateTimeFormatterBuilder().parseStrict().appendPattern(pattern).toFormatter().parse(text)));
System.out.println(MessageFormat.format("Lenient - {0}", new DateTimeFormatterBuilder().parseLenient().appendPattern(pattern).toFormatter().parse(text)));
输出:
Strict - {},ISO resolved to 2011-01-02T04:21:32
Exception in thread "main" java.time.format.DateTimeParseException: Text '02011104:21:32' could not be parsed at index 8