Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert a time stamp into database via ContentValues

In Android, is it possible to insert a time stamp into a database using ContentValues? When I try to add it using something like this:

ContentValues args = new ContentValues();       
args.put(MY_DATE, my_date);

I get an error telling me that my_date needs to be a String. Any suggestions on how to achieve this?

like image 476
Kevin Bradshaw Avatar asked Aug 07 '10 23:08

Kevin Bradshaw


1 Answers

Neither Date nor Calendar are valid things to put in a ContentValues. The most efficient format, I think, is to convert the Date to milliseconds (getTime()) and store that in an INTEGER column.

like image 192
CommonsWare Avatar answered Oct 19 '22 20:10

CommonsWare