0

I've got a question about counting the weeks between the current date and the date on SQLite.

I am trying to put date data on DBAdapter Class to SharedMemory :

SharedPreferences user = getSharedPreferences(USER, 0);
SharedPreferences.Editor editor = user.edit();
editor.clear();
editor.putString("full_date", fullDate);

Now, on my Activity :

SharedPreferences sharedPreferences = getSharedPreferences(USER, 0);
fullDateM = sharedPreferences.getString("full_date","");

DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date today = null;
try {
    today = df.parse(fullDateM);
} catch (ParseException e1) {
    e1.printStackTrace();
}

Calendar now = Calendar.getInstance();
Calendar now2 = Calendar.getInstance();
now.getTime();
now2.setTime(today);

long milis1 = now2.getTimeInMillis();
long milis2 = now.getTimeInMillis();

long diff = milis2 - milis1;

long diffDays = diff / (24 * 60 * 60 * 1000);

But, I got an error to get a value of diffDays. And I've checked that fullDateM is not null, there's value = "2012-04-27". And another question : how to set diffDays to difference of weeks in that code?

wdyz
  • 185
  • 4
  • 19
  • What exactly is the error you're getting? – Shellum May 25 '12 at 17:52
  • i got an error : E/AndroidRuntime(29737): on line => now2.setTime(today); – wdyz May 25 '12 at 18:01
  • I'm not really sure how your code compiles. now2.setTime() takes a long as a parameter and you are passing it a Dat object. Can you post the entire stack trace please? – Shellum May 25 '12 at 18:10

0 Answers0