Ric*_*ich 1 java datetime java-8
我试图将一些日期字符串解析为日期值,但是,使用下面的代码,我遇到了异常:
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("Q'Q'uuuu - MMM");
String d = "3Q2016 - Aug";
System.out.println(LocalDate.parse(d, formatter));
Run Code Online (Sandbox Code Playgroud)
下面是例外
java.time.format.DateTimeParseException: Text '3Q2016 - Aug' could not be parsed: Unable to obtain LocalDate from TemporalAccessor: {MonthOfYear=8, QuarterOfYear=3, Year=2016},ISO of type java.time.format.Parsed
Run Code Online (Sandbox Code Playgroud)
查看异常,我看到了正确的数据,但是由于某种原因无法对其进行解析。
我看到的其他类似主题建议使用LocalDate或LocalDateTime,但均无效。
这是因为指定的字符串没有特定的日期可供选择。您可能需要使用YearMonth
代替,LocalDateTime
然后使用YearMonth.atDay(1)
进行转换,以获取每月的第一天。
归档时间: |
|
查看次数: |
391 次 |
最近记录: |