SQLite:以毫秒精度插入当前时间戳

时间:2013-12-17 09:05:29

标签: sql sqlite

我正在尝试将当前时间戳插入SQLite:

CREATE TABLE test (timestamp DATETIME);
INSERT INTO test VALUES(datetime('now'));

这确实创建了时间戳,但只有秒精度(时间戳看起来像2013-12-17 07:02:20)。是否可以添加毫秒?

1 个答案:

答案 0 :(得分:11)

Date and time functions referencedatetime(timestring, [modifiers...])相当于strftime('%Y-%m-%d %H:%M:%S', timestring, [modifiers...])

如果您想要小数秒,则必须使用%f而不是%S。因此,请使用strftime('%Y-%m-%d %H:%M:%f', 'now')