Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java 8: Pb with new java.time api

bsar69Jan 26 2014 — edited May 8 2014

Hello,

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

I'm using the latest build B124.

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 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 my code, and I can't figure out how I should proceed to convert the String to an Instant ...

Any suggestion welcome,

Best regards,

Bernard.

Comments
Post Details
Added on Jan 26 2014
5 comments
4,134 views