我知道替代方法來檢查下一個日期,但是我想知道在使用之前是否有任何忽略檢查時間的可能性。如何在使用之前檢查日期時忽略時間(日期d)
我有以下代碼
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
try {
if (fired == true) {
return;
} else {
// first time fired
fired = true;
}
String date = checkDigit(monthOfYear + 1) + "/"
+ checkDigit(dayOfMonth) + "/" + year;
strDate = date;
SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
Date d=df.parse(strDate);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, 1);
if(d.before(cal.getTime()))
{
etDOB.setText(strDate);
}
else
{
Toast.makeText(context, "Enter Valid Date Of Birth", Toast.LENGTH_SHORT).show();
etDOB.setText(" ");
}
} catch (ParseException e) {
e.printStackTrace();
}
}
d.before(cal.getTime()) checking date but if the selected Date is next Date than it also checking time
實施例:已選 日期值是feb 24 2013
所以d包含相同
cal.getTime() also contains feb 24 2013
但具有時間00:00:00 GMT+5:30
第一日期和第二有時間1:00:00 GMT+5:30
這導致條件失敗。所以我的問題是如何忽略之前檢查時間。
簡單,完成工作:) – Bruce 2016-04-09 06:50:56