开发者

SQLite3 and System.currentTimeMillis()

I want to generate exact same values using SQLite strftime() or any other function as that of System.currentTimeMillis() function in java. Is there a possible way ?

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

generates the current time but does not consider milliseconds but seconds. I want precision to miliseconds.

EDIT based on Axarydax answer

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

returns 129491124808.428 where %f returning 08.428 can I round this of to 129491124808

EDIT 2

ROUND(strftime('%s%f','now'))

returns 12949112开发者_如何学C4808.0 I dont want .0 at the end


According to this documentation, formatting string %f prints fractional seconds SS.SSS.


Time in seconds (epoch)

strftime('%s','now')

Current seconds + millis

strftime('%f','now')

Current seconds

strftime('%S','now')

So if you want just the millis you do:

strftime('%S','now') - strftime('%f','now')

And now add that to the time in seconds, you'll get millis as decimals

strftime('%s','now') + strftime('%f','now') - strftime('%S', 'now')

And now multiply it by 1000 and you get the current time in millis

CAST((strftime('%s','now') + strftime('%f','now') - strftime('%S', 'now')) * 1000 AS INTEGER)


SELECT CAST(strftime('%s%f','now') as INTEGER);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜