http://stackoverflow.com/questions/754684/how-to-insert-a-sqlite-record-with-a-datetime-set-to-now-in-android-applicatio
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);
複製代碼 |