TimeStamp Java和SQLite之间的区别 [英] TimeStamp Difference Between Java and SQLite
问题描述
您好我有SLQLite数据库,其中我有表water_logs
Hello I have and SLQLite database in which I have table water_logs
CREATE TABLE water_logs(
_id INTEGER PRIMARY KEY AUTOINCREMENT,
amount REAL NOT NULL,
icon INTEGER NOT NULL,
date INTEGER NOT NULL);
我以毫秒为单位存储日期。
I store date in milliseconds.
Calendar cal = Calendar.getInstance();
cal.getTimeInMillis();
我的问题是我希望使用从我的日期列中获取这一天strftime
功能。问题是tjat java日历时间戳与SLQLite时间戳不同
My problem is I want to get the day from the my date column using strftime
function. The problem is tjat java calendar timestamp is different from SLQLite time stamp
1436859563832 --> result from cal.getTimeInMillis();
1436607407--> SELECT strftime('%s','now')
我实际上要做的是按天分组记录。如果在日期列中粘贴SELECT strftime('%s','now')的值,则以下SQL查询可以正常工作
What I'm actually trying to do is to group records by day. The following SQL query works just fine if value of SELECT strftime('%s','now') is paste in the date column
SELECT SUM(amount), date(`date`) FROM water_logs
GROUP BY date(`date`, 'unixepoch')
推荐答案
在我看来,您使用的是两种不同的值类型。
Seems to me that you are using 2 different value types.
使用时
Calendar cal = Calendar.getInstance();
long time = cal.getTimeInMillis();
输出值为毫秒,如这里。
当你使用时
strftime('%s','now')
输出值为秒,如这里。
因此,这可能是导致两者不匹配的原因值。
当然,以秒为单位的值可能会经历一些舍入,这可能会稍微改变其值。
So, that might be the cause for the mismatch between the two values. Of course that the value in seconds might undergo some rounding which might change its value a little.
这篇关于TimeStamp Java和SQLite之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!