Storing date and time in SQL database on Android

I am trying to save 3 values ​​in a database that I created on an Android device. Values: NAME, DATE, and TIME. So my question is: what is the best approach for retrieving and storing the current DATE and TIME values ​​when they are inserted into the database?

So far, I have identified two ways to do this by making system calls in android, for example //values.put(TIME, System.currentTimeMillis());, or using SQL functions such as GETDATE(). But which is better?

If I'm heading in the wrong direction, let me know and point me in the right direction.

+3
source share
2 answers

Using SQL functions will be more compatible with other tools using the same SQL engine.

ISO YYYY-MM-DD hh:mm:ss.fff - .

+2

sqlite docs :

  • ISO8601 ( "-- : : ." ).
  • REAL, , 24 4714 . B.C. .
  • INTEGER as Unix Time, 1970-01-01 00:00:00 UTC.

TEXT, Doug Currie, INTEGER, java.util.Date. ( , REAL.)

INTEGER, :

// build a date from a Cursor
Date d = new Date(cursor.getLong(DATE_FIELD_INDEX));

// add a date to an SQLiteDatabase
final ContentValues values = new ContentValues();
values.put(DATE_FIELD, d.getTime());
db.insert(TABLE_NAME, null, values);

, ( ) , , . ( sqlite.)

+2

All Articles