这是很容易解析借记卡/信用卡的有效期限与乔达时间:Java 8:如何解析借记卡的到期日期?
org.joda.time.format.DateTimeFormatter dateTimeFormatter = org.joda.time.format.DateTimeFormat.forPattern("MMyy").withZone(DateTimeZone.forID("UTC"));
org.joda.time.DateTime jodaDateTime = dateTimeFormatter.parseDateTime("0216");
System.out.println(jodaDateTime);
日期:2016-02-01T00:00:00.000Z
我试图做同样的,但与Java时间API:
java.time.format.DateTimeFormatter formatter = java.time.format.DateTimeFormatter.ofPattern("MMyy").withZone(ZoneId.of("UTC"));
java.time.LocalDate localDate = java.time.LocalDate.parse("0216", formatter);
System.out.println(localDate);
输出:
引起:java.time.DateTimeException:Unabl e以获得来自TemporalAccessor的LocalDate :{MonthOfYear = 2,Year = 2016},ISO, 类型的UTC,时间格式为 java.time.LocalDate.from(LocalDate.java:368)at java .time.format.Parsed.query(Parsed.java:226)在 java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851) ...... 30多个
当我犯了一个错误以及如何解决它?
这似乎是一个本地日期不能是为广泛的一个字段你有想要的。本地需要一天的时间。 – Fallenreaper