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

DateTimeFormatter.ISO_DATE_TIME cannot parse "GMT0" ZoneId

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      linux

      Description

      A DESCRIPTION OF THE PROBLEM :
      java.time.format.DateTimeFormatter.ISO_DATE_TIME can write to string formats with a java.time.ZoneId of "GMT0", but cannot parse them.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a string representation of a time in the "GMT0" zone from a ZonedDateTime using ZonedDateTime#format(DateTimeFormatter.ISO_DATE_TIME).
      2. Attempt to parse the string back into a ZonedDateTime using ZonedDateTime#parse(DateTimeFormatter.ISO_DATE_TIME).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The formatter successfully parses the string it created. For example, "2019-05-20T11:28:38.154Z[GMT0]" is successfully parsed into a java.time.ZonedDateTime.
      ACTUAL -
      Exception in thread "main" java.time.format.DateTimeParseException: Text '2019-05-20T11:28:38.154Z[GMT0]' could not be parsed, unparsed text found at index 24
      at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1952)
      at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)

      ---------- BEGIN SOURCE ----------
      import java.time.ZonedDateTime;
      import java.time.ZoneId;
      import java.time.format.DateTimeFormatter;

      class Gmt0FormatTest {
          public static void main(String[] args) {
              String time = ZonedDateTime.now().toInstant().atZone(ZoneId.of("GMT0")).format(DateTimeFormatter.ISO_DATE_TIME);
              System.out.println(time); // e.g. "2019-05-20T11:28:38.154Z[GMT0]"
              System.out.println(ZonedDateTime.parse(time, DateTimeFormatter.ISO_DATE_TIME)); // expect the same time string; actually throws java.time.format.DateTimeParseException
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Change your computer's timezone to "GMT" or "UTC" rather than "GMT0", I guess.

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                psonal Pallavi Sonal
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: