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?