0

我有一个关于计算当前日期和 SQLite 日期之间的周数的问题。

我正在尝试将 DBAdapter 类上的日期数据放入 SharedMemory :

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

现在,在我的活动中:

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);

但是,我得到一个错误来获取diffDays. 而且我检查过它fullDateM不为空,有 value = "2012-04-27"。还有另一个问题:如何diffDays在该代码中设置周差?

4

0 回答 0