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

(date) Date getTime and toString interaction for some time values

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 6
    • core-libs
    • b48
    • generic
    • generic

      The following test shows two problems.

      One, the date of the Gregorian cutover changed between JDK 1.4 and later JDKs.

      Two, creating a Date from Calendar.getTime(), calling toString on it, then calling getTime on the Date, returns a different time than the Date originally started with.

      public class GregoTest {
           public static void main(String args[]) {
               System.out.println("Java:" + System.getProperty("java.version"));
               java.util.TimeZone jdkGMT = java.util.TimeZone.getTimeZone("GMT");
      // java.util.TimeZone.setDefault(jdkGMT);
               java.util.Calendar jdkCal = java.util.Calendar.getInstance(jdkGMT);
               jdkCal.clear();
               jdkCal.set(1582, java.util.Calendar.OCTOBER, 15);
               System.out.println("JDK time: " + jdkCal.getTime().getTime() );
               System.out.println("JDK time (str): " + jdkCal.getTime() );
               System.out.println("Day of month: " +
                   jdkCal.get(java.util.Calendar.DAY_OF_MONTH));
               Date co = jdkCal.getTime();
               System.out.println("Change over (Oct 15 1582) = " + co + " (" +
                   co.getTime() + ")");
               long a = jdkCal.getTime().getTime();
               Date c = jdkCal.getTime();
               c.toString();
               long b = c.getTime();

               if(a!=b) {
                   System.out.println("ERR: " + a + " != " + b);
               } else {
                   System.out.println(a + " = " + b);
               }
           }
      }

      ###@###.### 2005-05-23 20:39:49 GMT

            okutsu Masayoshi Okutsu
            dougfelt Doug Felt
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: