MySQL - how to store time with correct timezone? (from Java)

后端 未结 3 445
清歌不尽
清歌不尽 2020-12-11 10:50

I\'m using MySQL 5.0. I need to store date-time information in one column. I mean to use DATETIME or TIMESTAMP column type. But I have problem with

3条回答
  •  庸人自扰
    2020-12-11 11:34

    DATE, TIME, YEAR and DATETIME all store the respective date/time indications, just like taking a photograph of a calendar and/or clockface: they do not record the timezone in which the clock was set, so they don't represent any particular moment in time. They're useful for events that occur on a specific local date or at a specific local time (i.e. irrespective of timezone).

    TIMESTAMP stores a UTC timestamp (as seconds since the UNIX epoch), performing conversion to/from your session's time_zone as necessary: it represents a precise, unambiguous moment in time. This is what you want; just be sure to set your session variable as appropriate (with SET SESSION time_zone = ...).

    See MySQL Server Time Zone Support for more information.

提交回复
热议问题