SQLite 时间日期字段问题

1:建表的时候就设置好

CREATE TABLE testDate (
id INTEGER PRIMARY KEY AUTOINCREMENT,
t TIMESTAMP
DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE users(
username varchar(20),
userpwd varchar(20),
createtime TIMESTAMP default (datetime('Now','localtime'))

)

2:利用sqlite内部函数

mDb.execsql("INSERT INTO "+TABLE+" VALUES (datetime()) ");

datetime()函数要用引号包起来 当作字符串处理

3:直接把获得的date传给sqlite,格式不对,需要format下

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); ContentValues initialValues = new ContentValues(); initialValues.put("date_created",dateFormat.format(date)); long rowId = mDb.insert(DATABASE_TABLE,null,initialValues);

相关文章

SQLite架构简单,又有Json计算能力,有时会承担Json文件/RES...
使用Python操作内置数据库SQLite以及MySQL数据库。
破解微信数据库密码,用python导出微信聊天记录
(Unity)SQLite 是一个软件库,实现了自给自足的、无服务器...
安卓开发,利用SQLite实现登陆注册功能