我正在尝试在 Andoird 项目的 Sqlite 数据库中插入日期时间字段。尝试了很多这样的方法,但插入日期时间字段没有运气。以下是事实
1] 我的 Sqlite 字段是类型时间戳
2]数据库类
package com.gcm.pushandroid;
import java.util.Date;
public class Notifications {
//private variables
String _type;
String _time_stamp;
// Empty constructor
public Notifications(){
}
// constructor
public Notifications(String type, String timeStamp){
this._type = type;
this._time_stamp = timeStamp;
}
// getting ID
public String getType(){
return this._type;
}
// setting id
public void setType(String type){
this._type = type;
}
// getting timestamp
public String getTimeStamp(){
return this._time_stamp;
}
// setting
public void setTimeStamp(String time_stamp){
this._time_stamp = time_stamp;
}
}
3]这是代码
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_TYPE, notificationObj.getType());
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
values.put("time_stamp", dateFormat.format(date));
db.insert(TABLE_CONTACTS, null, values);
db.close();
不知道出了什么问题。帮助表示赞赏。谢谢