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

Incorrect Date from milliseconds that are less than the year 1582

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.8.0_101"
      Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Edition: Windows 10 Enterprise
      Version: 1607
      OS Build: 14393.1066

      A DESCRIPTION OF THE PROBLEM :
      If anyone tries to create Date object from milliseconds that are less than 1582 year, it will get wrong value.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      To reproduce this issue create Date object using Date(long date) constructor and pass into value that is less than 1582 year, for example: -14831769600000 = Monday, January 1, 1500 12:00:00 AM

      Create Java class as bellow:

      import java.util.Date;
      public class JavaDateBugTest {
          public static void main(String[] args) {
              Date date = new Date(-14831769600000L);
              System.out.println(date);
          }
      }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Thu Jan 01 00:00:00 EET 1500
      ACTUAL -
      Mon Dec 23 00:00:00 EET 1499

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.Date;

      import org.junit.Assert;
      import org.junit.Test;

      public class JavaDateBugTest {
          @Test
          public void createDateFromMilliseconds_ValueLessThan1582_ValueIsNotEqualsToExpected() {
              Date date = new Date(-14831769600000L);
              Assert.assertEquals("Thu Jan 01 00:00:00 EET 1500", date.toString());
          }
      }

      ---------- END SOURCE ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: