JDBC Timestamp & Date GMT issues

前端 未结 5 1095
夕颜
夕颜 2021-02-06 05:20

I have a JDBC Date column, which if a i use getDate is get the \'date\' part only 02 Oct 2009 but if i use getTimestamp i get the full \'date\

5条回答
  •  灰色年华
    2021-02-06 05:32

    That's the difference between Timestamp and other temporal types in MySQL. Timestamp is saved as Unix time_t in UTC but other types store date/time literally without zone information.

    When you call getTimestamp(), MySQL JDBC driver converts the time from GMT into default timezone if the type is timestamp. It performs no such conversion for other types.

    You can either change the column type or do the conversion yourself. I recommend former approach.

提交回复
热议问题