oikonomopo
oikonomopo

Reputation: 4065

How to android + sqlite + date + time?need date/time operations

I have an activity where i want to to save some measures data into a sqlite database(i will have only insert option).The xml is:

enter image description here

date / time is taking value(by date/time dialogs) after the create of this activity,then user can change it if he wants.

I want in another activity to have listview of measures by descending date + time.

I want also to be able to fetch the measures of last 1 / 7 / 30 days.

What is the best way to make the sqlite table?How i should save date + time?together?or not?as TEXT or REAL or INTEGER so that can i easily make the above operations?

Upvotes: 0

Views: 1094

Answers (1)

Jack Satriano
Jack Satriano

Reputation: 2029

You should use System.currentTimeMillis() and store that BIGINT value in the table. You can parse the time with something like this:

    SimpleDateFormat sdf = new SimpleDateFormat("MM dd,yyyy HH:mm");

    Date resultdate = new Date(yourmilliseconds);
    System.out.println(sdf.format(resultdate));

Source: How to transform currentTimeMillis to a readable date format?

Upvotes: 3

Related Questions