VISHAL DAGA
VISHAL DAGA

Reputation: 4309

How to retrieve DATETIME format from Sqlite database

I have stored date (java.util.date object) in a DATETIME field of a Sqlite table. Now, how to retrieve this date which would be of the same format as java.util.date. Actually I want to compare the time difference (in milliseconds) between current date and the store date.

Upvotes: 8

Views: 24205

Answers (3)

janoulle
janoulle

Reputation: 1948

Here's code that I used to perform what @Gopinath suggested:

Calendar t = new GregorianCalendar();
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/YYYY",Locale.getDefault());
java.util.Date dt = sdf.parse(c.getString(4)); //replace 4 with the column index
t.setTime(dt);

Upvotes: 14

Samir Mangroliya
Samir Mangroliya

Reputation: 40426

In java SimpleDateFormat

http://developer.android.com/reference/java/text/SimpleDateFormat.html

if you want millisecons anyDAteObject.getTime();

Upvotes: 2

Gopinath
Gopinath

Reputation: 13051

Retrieve as Cursor.getString() and pass that value to SimpleDateFormat to make the date object. There is no straight method for getting the date object.

Upvotes: 16

Related Questions