I have made a database todo list application and would like to add the current time to it. However, I do not know how to do this in Java.
public void addProduct(ListItem product) {
ContentValues values = new ContentValues();
values.put(COLUMN_TODO, product.getToDo());
values.put(COLUMN_FOR, product.getAccFor());
SQLiteDatabase db = getWritableDatabase();
db.insert(TABLE_LIST, null, values);
db.close();
}
This is my current function to add an object to the database:
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "productDB.db";
public static final String TABLE_LIST = "List";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_TODO = "ToDo";
public static final String COLUMN_FOR = "accFor";
private String University = "University";
private String Work = "Work";
private String Personal = "Personal";
And these are the variables I declare at the start of the database, if it is possible using Android Studio I would like to also add the current time into the database so it can be displayed alongside the other values, GPS would be nice also, however, I feel this may be a little advanced.
public void onCreate(SQLiteDatabase db) {
String query = "CREATE TABLE " + TABLE_LIST + "(" +
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
COLUMN_TODO + " TEXT, " +
COLUMN_FOR + " TEXT " +
");";
db.execSQL(query);
}
This is the code for creation of the table.