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

Timestamp.valueOf() add one hour to the timestamp because of daylight saving time

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      OS: MacOs/Linux
      Java: 1.8/11

      A DESCRIPTION OF THE PROBLEM :
      // for both java 8 and 11 I can see the following code snippet add 1 hour to the Timestamp
      Timezone Pacific Standard Time (PST)

      public class TestSQLTimstampParser {
          public static void main(String[] args) {
              //2019-03-10 02:46:18.792035
              java.sql.Timestamp ts = Timestamp.valueOf("2019-03-10 02:46:18.792035");
              java.sql.Timestamp ts1 = Timestamp.valueOf("2019-03-10 02:46:18");
              System.out.println(ts); // 2019-03-10 03:46:18.792035
              System.out.println(ts1);

              // 2019-08-13 04:51:43
              java.sql.Timestamp ts2 = Timestamp.valueOf("2019-08-13 04:51:43");
              System.out.println(ts2); // output 2019-08-13 04:51:43.0
          }
      }


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      public class TestSQLTimstampParser {
          public static void main(String[] args) {
              //2019-03-10 02:46:18.792035
              java.sql.Timestamp ts = Timestamp.valueOf("2019-03-10 02:46:18.792035");
              java.sql.Timestamp ts1 = Timestamp.valueOf("2019-03-10 02:46:18");
              System.out.println(ts); // 2019-03-10 03:46:18.792035
              System.out.println(ts1);

              // 2019-08-13 04:51:43
              java.sql.Timestamp ts2 = Timestamp.valueOf("2019-08-13 04:51:43");
              System.out.println(ts2); // output 2019-08-13 04:51:43.0
          }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      2019-03-10 02:46:18.792035
      2019-03-10 02:46:18.0
      2019-08-13 04:51:43.0
      ACTUAL -
      2019-03-10 03:46:18.792035
      2019-03-10 03:46:18.0
      2019-08-13 04:51:43.0

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              Assignee:
              lancea Lance Andersen
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: