The fix for JDK-8033662 enabled a ZonedDateTime to be parsed when withZone() is used. Unfortunately, the fix did not allow an Instant to be parsed. More generally, there is no current way to parse an instant except using the appendInstant() method of the formatter builder. @Test public void test_parse_Instant_withZone1() { DateTimeFormatter fmt = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss ").appendZoneId().toFormatter(); TemporalAccessor acc = fmt.parse("2014-06-30 01:02:03 Europe/Paris"); Instant actual = Instant.from(acc); assertEquals(actual, ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, PARIS).toInstant()); } @Test public void test_parse_Instant_withZone2() { DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(PARIS); TemporalAccessor acc = fmt.parse("2014-06-30 01:02:03"); Instant actual = Instant.from(acc); assertEquals(actual, ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, PARIS).toInstant()); } Tests fail in the from() method because it does not make available INSTANT_SECONDS even though sufficient data is available.
|