Skip to main content

Java 8: Possible bug in java.time API.

Please note these forums are being decommissioned and use the new and improved forums at
2 replies [Last post]
Joined: 2014-01-26


I'm trying to use the new java.time api that comes with Java 8, build B124 (I already know joda-time).

I've a String "01/08/2012_00:00:01", I know that the time ref. is UTC, and I want to convert it to an 'Instant';

I tried:

DateTimeFormatter FORMAT_DT = DateTimeFormatter.ofPattern("dd/MM/yyyy_HH:mm:ss").withZone(ZoneOffset.UTC);
Instant instant = Instant.from(FORMAT_DT.parse("01/08/2012_00:00:01"));

But it fails on the second line with following error:

java.time.DateTimeException: Unable to obtain Instant from TemporalAccessor: {},ISO resolved to 2012-08-01T00:00:01 of type java.time.format.Parsed
at java.time.Instant.from(Unknown Source)

I don't understand what's wrong with this code - it seems compliant with the JavaDoc -, so I'm wondering if this is a bug or not ...

Note: If I use first a LocalDateTime instead of an Instant it works:

LocalDateTime ldt = LocalDateTime.from(FORMAT_DT.parse("01/08/2012_00:00:01"));
Instant instant = Instant.from(ldt.atZone(ZoneOffset.UTC));

But it seems strange to have to go through a LocalDateTime to convert a String to an Instant ...

Any comments welcome,

Best regards,


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2004-11-15

please file a bug at

Joined: 2014-01-26

Ok, just done.