Timezones in SQL DATE vs java.sql.Date

后端 未结 7 778
天涯浪人
天涯浪人 2020-11-28 04:11

I\'m getting a bit confused by the behaviour of the SQL DATE data type vs. that of java.sql.Date. Take the following statement, for example:



        
7条回答
  •  Happy的楠姐
    2020-11-28 04:56

    Both java.util.Date and the Oracle/MySQL Date objects are simply representations of a point in time regardless of location. This means that it is very likely to be internally stored as the number of milli/nano seconds since the "epoch", GMT 1970-01-01 00:00:00.

    When you read from the resultset, your call to "rs.getDate()" tells the resultset to take the internal data containing the point in time, and convert it to a java Date object. This date object is created on your local machine, so Java will choose your local timezone, which is CET for Zurich.

    The difference you are seeing is a difference in representation, not a difference in time.

提交回复
热议问题