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

SimpleDateFormat("yyyy/ww") returns wrongly parsed WEEK no.

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.8.0_92"

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [版本 6.3.9600]
      Windows 8.1

      A DESCRIPTION OF THE PROBLEM :
      When I use SimpleDateFormat("yyyy/ww") to parse the date of "2015-12-31", it returns the week number as 1.

      Apparently, this day is in last week of 2015, instead the first one.

      I also tried several days before 2015-12-31, and such days of other years, the week number returned is always 1.

      PS:
      "2015-12-26" produces 2015/52, but
      "2015-12-27" produces 2015/01.

      Please try the attached code below.

      REGRESSION. Last worked in version 8u92

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.8.0_92"
      Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Please run the attached source code to see more details.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Date: 2015/12/31
      Week: 2015/53

      or

      Date: 2015/12/31
      Week: 2016/01
      ACTUAL -
      Date: 2015/12/31
      Week: 2015/01

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.text.SimpleDateFormat;
      import java.util.Calendar;

      public class ReportBug {
      public static void main(String[] args) {
      SimpleDateFormat
      dfDateOnly = new SimpleDateFormat("yyyy/MM/dd"),
      dfYearWeek = new SimpleDateFormat("yyyy/ww");

      Calendar c = Calendar.getInstance();
      c.set(2015, 11, 31);

      System.out.println("Date: " + dfDateOnly.format(c.getTime()));
      System.out.println("Week: " + dfYearWeek.format(c.getTime()));
      }
      }
      ---------- END SOURCE ----------

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

              Created:
              Updated:
              Resolved: