Inserting datetime in sqlite database android

android, sqlite

Solution

Convert date/time to milliseconds and you get a `long`. Then you just insert the `long` value in database.

You can add date/time values together if they are in milliseconds.

--EDITED--

    Date myDate = new Date();
    long timeMilliseconds = myDate.getTime();
    //add 1 hour
    timeMilliseconds = timeMilliseconds + 3600 * 1000; //3600 seconds * 1000 milliseconds
    //To convert back to Date
    Date myDateNew = new Date(timeMilliseconds);

In SQLite the java `long` value is stored as a `int`.

Problem

how can i insert datetime data in my sqlite database using contentvalues not using raw query?. datetime('now') insert itself(text) not the time, and can i add addittional hours to the current time? like, when i press button "1HOUR" it would insert the currenttime + 1 hour in the sqlite database..thanks, kinda confused..

Original source