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

SimpleDateFormat year format YYYY gives me 2020 already

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Linux / Windows / Latest JDK as well

      A DESCRIPTION OF THE PROBLEM :
      When using SimpleDateFormat format (dd/MMM/YYYY:HH:mm:ss Z), I am seeing YEAR returned as 2020 from 29th Dec 2019. However, "yyyy" (small case) works as expected. This behavior is noticed only from 29th December 2019 and this would again start returning year as 2020 from Jan 1st. (so only 29th, 30th and 31st of Dec 2019, we will have this problem)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1.Specify the format string as "dd/MMM/YYYY:HH:mm:ss Z" in SimpleDateFormat constructor.
      2. Use current Date
      3. Format the date using above formatter.
      4. Print the date


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Current Time 1577691758596
      30/Dec/2019:13:12:38 +0530
      ACTUAL -
      Current Time 1577691758596
      30/Dec/2020:13:12:38 +0530

      ---------- BEGIN SOURCE ----------
      SimpleDateFormat formatter = new SimpleDateFormat("dd/MMM/YYYY:HH:mm:ss Z", Locale.US);
      formatter.setTimeZone(TimeZone.getDefault());
      long currentTime = System.currentTimeMillis();
      System.out.println("Current Time " + currentTime);
              String dateString = formatter.format(new Date(currentTime));
              System.out.println(dateString);
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      changing YYYY to yyyy fixes the problem.

      FREQUENCY : always


            tongwan Andrew Wang
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: