有些sqlite中存储date的使用备忘.
-
SQLiteDatabase.execSQL so you can enter a raw SQL query.
mDb.execSQL("INSERT INTO "+DATABASE_TABLE+" VALUES (null, datetime()) ");
-
Or the java date time capabilities :
// set the format to sql date time
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);
读取
String str = "1987-07-28 12:34:56";
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date d = df.parse(str);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}