SQLite将默认时间戳记存储为unixepoch
定义关系时,我想在insert插入时更新属性到时间戳。例如,我现在有一个工作表
CREATE TABLE t1( id INTEGER PRIMARY KEY AUTOINCREMENT,time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,txt TEXT); 这是更新插入的时间戳,例如insert into t1(txt)values(‘hello’)添加行1 | 2012-07-19 08:07:20 | hello |。但是,我希望将此日期格式化为unixepoch格式。 我读了docs,但这还不清楚。例如,我将表关系修改为TIMESTAMP DEFAULT DATETIME(‘now’,’unixepoch’),但是我收到错误。在这里,如在文档中,现在是我的时间字符串和unixepoch是修饰符,但它没有工作。有人可以帮助我如何将其格式化为unixepoch时间戳? 使用strftime:sqlite> select strftime('%s','now'); 1342685993 在CREATE TABLE中使用它,如下所示: sqlite> create table t1 ( ...> id integer primary key,...> time timestamp default (strftime('%s','now')),...> txt text); sqlite> insert into t1 (txt) values ('foo'); sqlite> insert into t1 (txt) values ('bar'); sqlite> insert into t1 (txt) values ('baz'); sqlite> select * from t1; 1|1342686319|foo 2|1342686321|bar 3|1342686323|baz 见https://www.sqlite.org/lang_createtable.html#tablecoldef
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |