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

Date.setDate Chaos caused by multiple times

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      Date date = new Date();
      date.setDate(0);
      date.setDate(n);

      the funciotn "public void setDate(int date)" has one parameter "int" .The frequently-used range is 1-31,but when input 0,the date will change to one month prior。

      for example :
      today is 2022-07-05 ,i want to get 2022-06-05 ,then i make code:
      Date date = new Date();
      int day=date .getDate();
      date.setDate(0);
      date.setDate(date );

      the result is 2022-07-05 ,nothing has changed.
      and i write something after line 3(date.setDate(0);) just as print or get,the result is 2022-06-05


      Date date = new Date();
      int day=date .getDate();
      date.setDate(0);
      date.getMonth();//System.out.println(date);....
      date.setDate(date );



      REGRESSION : Last worked in version 8

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Date date = new Date();
      int day=date .getDate();
      date.setDate(0);
      date.setDate(date );

      ACTUAL -
      2022-07-05

      FREQUENCY : always


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

              Created:
              Updated:
              Resolved: