SQLite CURRENT_TIMESTAMP always 1970-01-01

匿名 (未验证) 提交于 2019-12-03 00:56:02

问题:

I have the following defining a table:

CREATE TABLE players(playerid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,                      name VARCHAR(20) NOT NULL UNIQUE,                      added DATETIME DEFAULT CURRENT_TIMESTAMP); 

The CURRENT_TIMESTAMP relentlessly inserts 1970-01-01. I am loosely aware of the significance of this date and how some timestamps are a positive/negative offset from it; however, from what I've read elsewhere, my default timestamp should use the current time/date, as is suggests. Also, should a timestamp not include the time (from 1970 or otherwise)?

Thanks! :)

回答1:

I just had an epiphany and realised I was being an idiot. I am using Java to connect to the database and was using resultSet.getDate("added"), which apparently is not suited to this purpose, and returns 1970-01-01. getString("added") confirmed my mistake, and returned exactly what I wanted to see :)



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!