Java 8+ ISO8601 date formatting with LocalDate, Instant and DateTimeFormatter

ISO8601 datetime formats are commonly used especially when storing dates as Strings. Java 8’s java.time.format.DateTimeFormatter has a predefined formatter to format as ISO8601, DateTimeFormatter.ISO_INSTANT, but applying it to a DateTime instance gives an exception:

String formattedDate =;
java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: InstantSeconds
at java.time.LocalDate.get0(

If you check the JavaDocs (here) there is a comment that states:

"This is a special case formatter intended to allow a human readable form of an Instant"

Changing this code to use an Instant instead:


works as expected:


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.