Sqlite: CURRENT_TIMESTAMP is in GMT, not the timezone of the machine

后端 未结 11 919
小蘑菇
小蘑菇 2020-11-29 16:36

I have a sqlite (v3) table with this column definition:

\"timestamp\" DATETIME DEFAULT CURRENT_TIMESTAMP

The server that this database live

11条回答
  •  孤城傲影
    2020-11-29 17:06

    I found on the sqlite documentation (https://www.sqlite.org/lang_datefunc.html) this text:

    Compute the date and time given a unix timestamp 1092941466, and compensate for your local timezone.

    SELECT datetime(1092941466, 'unixepoch', 'localtime');
    

    That didn't look like it fit my needs, so I tried changing the "datetime" function around a bit, and wound up with this:

    select datetime(timestamp, 'localtime')
    

    That seems to work - is that the correct way to convert for your timezone, or is there a better way to do this?

提交回复
热议问题