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

xzv2uavs  于 2023-06-06  发布在  SQLite
关注(0)|答案(1)|浏览(227)

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

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

这确实创建了时间戳,但只有秒精度(时间戳看起来像2013-12-17 07:02:20)。有没有可能把毫秒也加进去?

lstz6jyr

lstz6jyr1#

Date and time functions reference表示datetime(timestring, [modifiers...])等价于strftime('%Y-%m-%d %H:%M:%S', timestring, [modifiers...])
如果你想要小数秒,你必须使用%f而不是%S。所以使用strftime('%Y-%m-%d %H:%M:%f', 'now')

CREATE TABLE test (timestamp DATETIME);
INSERT INTO test VALUES(strftime('%Y-%m-%d %H:%M:%f', 'now'));

相关问题