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

后端 未结 11 924
小蘑菇
小蘑菇 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 16:41

    In the (admitted rare) case that a local datatime is wanted (I, for example, store local time in one of my database since all I care is what time in the day is was and I don't keep track of where I was in term of time zones...), you can define the column as

    "timestamp" TEXT DEFAULT (strftime('%Y-%m-%dT%H:%M','now', 'localtime'))
    

    The %Y-%m-%dT%H:%M part is of course optional; it is just how I like my time to be stored. [Also, if my impression is correct, there is no "DATETIME" datatype in sqlite, so it does not really matter whether TEXT or DATETIME is used as data type in column declaration.]

提交回复
热议问题