public void startDateTapped(View view) {
DatePickerDialog datePickerDialog = new DatePickerDialog(EditAppointmentActivity.this,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, final int year, final int monthOfYear, final int dayOfMonth) {
if (view.isShown()) { //Validation method because for some reason onDateSet is called twice... so timepicker is called twice
Date appointmentStartDate = new Date();
try {
appointmentStartDate.setTime(appointmentDF.parse(appointment.startTime).getTime());
} catch (ParseException e) {
e.printStackTrace();
}
final Calendar c = Calendar.getInstance();
c.setTime(appointmentStartDate);
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
mHour = c.get(Calendar.HOUR_OF_DAY);
mMinute = c.get(Calendar.MINUTE);
CustomTimePickerDialog timePickerDialog = new CustomTimePickerDialog(EditAppointmentActivity.this, TIME_PICKER_INTERVAL, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
SimpleDateFormat df = new SimpleDateFormat("d/M/yyyy H:m", Locale.US);
SimpleDateFormat targetDateFormat = new SimpleDateFormat("dd/MM/yyyy h:mma", Locale.US);
minute = getRoundedMinute(minute);
String unformattedTimeString = dayOfMonth + "/" + (monthOfYear + 1) + "/" + year + " " + hourOfDay + ":" + minute; //+1 because month starts from 0
try {
Date unformattedTime = df.parse(unformattedTimeString);
String formattedTimeString = targetDateFormat.format(unformattedTime);
startDateText.setText(formattedTimeString);
} catch (ParseException e) {
e.printStackTrace();
}
}
}, mHour, mMinute, false);
timePickerDialog.show();
}
}
}, mYear, mMonth, mDay);
try {
datePickerDialog.getDatePicker().setMinDate(appointmentDF.parse(appointment.startTime).getTime());
} catch (ParseException e) {
e.printStackTrace();
}
datePickerDialog.show();
}
然后给我一个错误:
引起者:java.lang.IllegalArgumentException:fromDate:7月30日星期一 18:19:48 GMT + 08:00 2018不早于日期:7月30日星期一18:19:48 GMT + 08:00 2018