2010-09-11 160 views
28

如何獲取Sqlite中的當前時間戳? current_time,current_date,current_timestamp都返回格式化日期,而不是long。sqlite中的Unix時間戳?

sqlite> insert into events (timestamp) values (current_timestamp); 
sqlite> insert into events (timestamp) values (current_date); 
sqlite> insert into events (timestamp) values (current_time); 
sqlite> select * from events; 
1|2010-09-11 23:18:38 
2|2010-09-11 
3|23:18:51 

我想要什麼:

4|23234232 

回答

66

docs提到這個方法:

SELECT strftime('%s', 'now'); 
1284248196 

而這其中包括小數部分:

SELECT (julianday('now') - 2440587.5) * 86400.0; 
1284248196.65098 

兩個代表Unix Time,自1970年1月1日起經過的秒數。