2013-12-17 96 views
8

我試圖爲當前時間戳插入SQLite的:SQLite的:將當前的時間戳和毫秒精度

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

這將創建一個時間戳,但只能用秒精度(時間戳看起來像2013-12-17 07:02:20)。還有可能加上毫秒嗎?

回答

9

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')

+0

實際上,我用'replace(strftime('%y%m%d%H%M%f','now'),'。','')'作爲數字來存儲它。 –