当我在没有该比较的情况下执行以下代码时,它可以工作,但是通过该比较它会失败。
感谢 Oleg Vaskevich,用他的观点更新了代码。日期范围是 1-31,不像月份 0-11 和 Date(int,int,int) 替换为 Date(long)
编辑代码
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, -1);
int month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);
int day=cal.get(Calendar.DATE); // for dynamic reset rates
callSince.setText("since(dd/mm/yyyy) :" + day + "/" + (month+1) + "/" + year );
// month+1 because month {0-11}
Date resetDateDate = new Date(cal.getTimeInMillis());
Calendar resetDateCal = Calendar.getInstance();
resetDateCal.setTime(resetDateDate);
String resetDate = String.valueOf(resetDateCal.getTimeInMillis());
/*
* CALL INCOMING
*/
projection = new String[] {CallLog.Calls.DURATION };
selection = CallLog.Calls.TYPE + "=? AND " + CallLog.Calls.DATE + " >=?" ;
selectionArgs = new String[] { (String.valueOf(CallLog.Calls.INCOMING_TYPE)) , (resetDate) };
try
{
Cursor cIn = getContentResolver().query(CallLog.Calls.CONTENT_URI, projection, selection, selectionArgs, sortOrder);
startManagingCursor(cIn);