Java MySQL Timestamp time zone problems

后端 未结 3 683
遇见更好的自我
遇见更好的自我 2021-01-02 16:20

I have a java.util.Date object, and I need to insert it into a datetime field in MySQL in UTC format.

java.util.Date date = myDate         


        
3条回答
  •  醉梦人生
    2021-01-02 16:52

    Check this link for explanation for MySQL (and you shouldn't try to apply advices about Oracle to MySQL).

    The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.

    MySQL converts TIMESTAMP values from the current time zone to UTC for storage, and back from UTC to the current time zone for retrieval. (This does not occur for other types such as DATETIME.) By default, the current time zone for each connection is the server's time.

提交回复
热议问题