我花了 1 天的时间来比较两次,但直到现在还没有值得的结果。我基本上是在尝试比较两个不同的时间,我想避免第一次存储数据 id 少于第二次,但我不能。另外,相等的部分工作顺利,但第二部分不工作
@Override
public void onTimeSet(int id, TimePicker view, int hourOfDay, int minute) throws ParseException {
String AM_PM = " AM";
String pattern = "HH:mm";
SimpleDateFormat format = new SimpleDateFormat(pattern);
String mm_precede = "";
if (hourOfDay >= 12) {
AM_PM = " PM";
if (hourOfDay >=13 && hourOfDay < 24) {
hourOfDay -= 12;
}
else {
hourOfDay = 12;
}
} else if (hourOfDay == 0) {
hourOfDay = 12;
}
if (minute < 10) {
mm_precede = "0";
}
if (id == 1 && id ==2) {
Date date1 = format.parse(sTimeApp.getText().toString());
Date date2 = format.parse(eTimeApp.getText().toString());
DateTime da1 = new DateTime(date1);
DateTime da2 = new DateTime(date2);
System.out.println("Date" + date1);
System.out.println("Date" + date1);
if (da1.equals(da2) ){
Toast.makeText(this, "Error , Time should be different ", Toast.LENGTH_SHORT).show();
return;
}else if (da1.isBefore(da2)){
Toast.makeText(this, "Error , Time should be different ", Toast.LENGTH_SHORT).show();
return;
}
}
// if (sTimeApp.equals(eTimeApp) ) {
// Toast.makeText(this, "Error , Time should be different ", Toast.LENGTH_SHORT).show();
// return;
// }
if (id == 1) {
if (minute <= 9) {
sTimeApp.setText(hourOfDay + ":" + mm_precede + minute + AM_PM);
} else {
sTimeApp.setText(hourOfDay + ":" + mm_precede + minute + AM_PM);
}
} else if (id == 2) {
if (minute <= 9) {
eTimeApp.setText(hourOfDay + ":" + mm_precede + minute + AM_PM);
} else {
eTimeApp.setText(hourOfDay + ":" + mm_precede + minute + AM_PM);
}
}
}
}