我想执行一个简单的例子,用模式解析字符串到日期.
String input = "Sep 31 2013";
LocalDate localDate = LocalDate.parse(input,
DateTimeFormatter.ofPattern("MMM d yyyy"));
Run Code Online (Sandbox Code Playgroud)
它抛出异常:
Exception in thread "main" java.time.format.DateTimeParseException: Text 'Sep 31 2013' could not be parsed at index 0
at java.time.format.DateTimeFormatter.parseResolved0(Unknown Source)
at java.time.format.DateTimeFormatter.parse(Unknown Source)
at java.time.LocalDate.parse(Unknown Source)
at lambda.DateTime.main(DateTime.java:78)
Run Code Online (Sandbox Code Playgroud)
我使用java 8中的java.time包.
我假设你有非英语Locale.如果要用英语解析,请使用相应的Locale
String input = "Sep 31 2013";
LocalDate localDate = LocalDate.parse(input, DateTimeFormatter
.ofPattern("MMM d yyyy").withLocale(Locale.ENGLISH));
Run Code Online (Sandbox Code Playgroud)
或任何其他英语Locale:美国,加拿大,英国等
或者,为您的Locale,ru_RU传递俄语日期字符串,即.Sep俄语在哪里可以适当地解析
| 归档时间: |
|
| 查看次数: |
4804 次 |
| 最近记录: |