我对 sqlite 中的 unix 时间戳有疑问。
我想将 System.currentTimeMillis() 的结果存储在 sqllite(整数)中。但是当我从数据库中读取存储值时,我总是得到一个负值,比如 -203027418,而不是我存储的值,比如 1494445606119
这是我的数据库的方案:
// Database creation sql statement
private static final String CREATE_ROUTE = "create table "
+ TABLE_ROUTE + "("
+ ROUTE_COLUMN_ID + " integer primary key autoincrement, "
+ ROUTE_COLUMN_DATE + " integer);";
private static final String CREATE_LOCATION = " create table "
+ TABLE_LOCATION + "("
+ LOCATION_COLUMN_ID + " integer primary key autoincrement, "
+ LOCATION_COLUMN_ROUTEID + " integer, "
+ LOCATION_COLUMN_LAT + " real, "
+ LOCATION_COLUMN_LONG + " real, "
+ LOCATION_COLUMN_DATE + " integer, "
+ " FOREIGN KEY(" + LOCATION_COLUMN_ROUTEID + ") REFERENCES " + TABLE_ROUTE + "(" + ROUTE_COLUMN_ID + "));";`
调试截图:
在存储时,值看起来不错: value in object
但是,当我从数据库读取时,我只得到这样的值: value after reading from DB
有人知道这里发生了什么吗?
最佳答案
发生这种情况是因为 SQLite 需要秒的时间戳,而不是毫秒。当您尝试以毫秒为单位存储时间戳时,会发生溢出并且 SQLite 会保存负整数而不是时间戳。
关于java - sqlite中的android unix时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43901742/