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

Calendar.set() does not set the date correctly

XMLWordPrintable

    • 1.2beta3
    • sparc
    • solaris_2.5.1
    • Not verified



        Name: mf23781 Date: 12/18/97


        The set() method of the Calendar class does not set the "day of
        the year" correctly. Example follows:

        import java.util.Calendar;
        import java.util.GregorianCalendar;
        import java.util.Date;
        import java.text.SimpleDateFormat;
        import java.text.FieldPosition;

        public class CalTestCase
        {
          public static void main(String args[])
          {
            GregorianCalendar cal = (GregorianCalendar)Calendar.getInstance();
            cal.set(Calendar.YEAR, 1997);
            cal.set(Calendar.DAY_OF_YEAR, 1);
            Date d = cal.getTime(); // Should be Jan 1
            System.out.println(d);
          }
        }

        Instead of setting the date to January 1st, the date is set to
        today's date!

        This works on 1.1.2, but appears to be broken on all 1.1.4 ports.

        ======================================================================

              aliusunw Alan Liu (Inactive)
              miflemi Mick Fleming
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: