我正在制作一个应用程序来存储书名、添加日期和需要归还书的日期。下面,我展示了where
获取从今天到两天之间归还的所有书籍的语句,以列表视图的形式返回。但是,它不起作用,我不确定我哪里出错了:
public Cursor fetchAllDue() {
//get todays date
Calendar cal=Calendar.getInstance();
int currentDay=cal.get(Calendar.DAY_OF_MONTH);
//Add days on to todays date
cal.set(Calendar.DAY_OF_MONTH, currentDay+2);
cal.getTime(); //Result
//format back to string
String formattedDate = new SimpleDateFormat("dd-MM-yyyy HH:mm").format(cal.getTime());
//get todays date
Calendar cal1=Calendar.getInstance();
int currentDay1=cal1.get(Calendar.DAY_OF_MONTH);
//Atodays date
cal1.set(Calendar.DAY_OF_MONTH, currentDay1);
cal1.getTime(); //Result
//format back to string
String formattedDate1 = new SimpleDateFormat("dd-MM-yyyy HH:mm").format(cal1.getTime());
//body = date added, needs to be changed
return mDb.query(DATABASE_TABLE, new String[] { KEY_ROWID, KEY_TITLE,
KEY_BODY, KEY_EXTRA, KEY_DUE }, KEY_DUE + " BETWEEN 'formattedDate1' and 'formattedDate2'", null, null, null, null);
}
这是为“到期日”输入日期时的代码:
//convert string to int.
int myNum = Integer.parseInt(editbox3.getText().toString());
//get todays date
Calendar cal=Calendar.getInstance();
int currentDay=cal.get(Calendar.DAY_OF_MONTH);
//Add days on to todays date
cal.set(Calendar.DAY_OF_MONTH, currentDay+myNum);
cal.getTime(); //Result
//formate back to string
String formattedDate = new SimpleDateFormat("dd-MM-yyyy HH:mm").format(cal.getTime());
bundle.putString(NotesDbAdapter.KEY_DUE,formattedDate
.toString());
日期都是字符串。任何人都可以帮忙吗?