Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8171199

DateTimeFormatter.ISO_INSTANT can't work with LocalDateTime

XMLWordPrintable

    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_111"
      Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      LocalDateTime ldtn = LocalDateTime.now();
      DateTimeFormatter fmtr = DateTimeFormatter.ISO_INSTANT;
      String tmStr = ldtn.format(fmtr);

      this code lines cause Exception "Exception in thread "main" java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: InstantSeconds"

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Get any LocalDateTime and attempt format it by predefined formatter DateTimeFormatter.ISO_INSTANT

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      correct formatted String as the result of format method call
      ACTUAL -
      throwed Exception

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: InstantSeconds
      at java.time.LocalDate.get0(Unknown Source)
      at java.time.LocalDate.getLong(Unknown Source)
      at java.time.LocalDateTime.getLong(Unknown Source)
      at java.time.format.DateTimePrintContext.getValue(Unknown Source)
      at java.time.format.DateTimeFormatterBuilder$InstantPrinterParser.format(Unknown Source)
      at java.time.format.DateTimeFormatterBuilder$CompositePrinterParser.format(Unknown Source)
      at java.time.format.DateTimeFormatter.formatTo(Unknown Source)
      at java.time.format.DateTimeFormatter.format(Unknown Source)
      at java.time.LocalDateTime.format(Unknown Source)
      at test.test.main(test.java:51)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package test;

      import java.time.LocalDateTime;
      import java.time.format.DateTimeFormatter;

      public class test {
      public static void main(String[] args) {//throws URISyntaxException {
      LocalDateTime ldtn = LocalDateTime.now();
      DateTimeFormatter fmtr = DateTimeFormatter.ISO_INSTANT;

      String tmStr = ldtn.format(fmtr);
      String debStr = "xyz"; // written for debug purpose
      }
      }

      ---------- END SOURCE ----------

            psonal Pallavi Sonal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: