小编dro*_*guy的帖子

如何在Android应用程序中插入日期时间设置为"now"的SQLite记录?

比如说,我们创建了一个表格:

create table notes (_id integer primary key autoincrement, created_date date)
Run Code Online (Sandbox Code Playgroud)

要插入记录,我会使用

ContentValues initialValues = new ContentValues(); 
initialValues.put("date_created", "");
long rowId = mDb.insert(DATABASE_TABLE, null, initialValues);
Run Code Online (Sandbox Code Playgroud)

但是如何将date_created列设置为now?为了说清楚,

initialValues.put("date_created", "datetime('now')");
Run Code Online (Sandbox Code Playgroud)

不是正确的解决方案.它只是将列设置为"datetime('now')"文本.

sqlite android content-values

107
推荐指数
6
解决办法
22万
查看次数

标签 统计

android ×1

content-values ×1

sqlite ×1