我有两个日历字段,我有两个条件要申请 1.不允许用户选择过去日期表示应用程序仅允许用户从今天开始选择日期 2.不允许用户选择从出发日期之前的TO日期
这是我正在使用的代码
ngOnDestroy() {
this.orderSubscriber.unsubscribe();
}
答案 0 :(得分:0)
停用过去的日期
datePicker.setMinDate(System.currentTimeMillis() - 1000);
比较和到达日期
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date strDate = sdf.parse(valid_until);
if (new Date().after(strDate)) {
//print Toast
}
答案 1 :(得分:0)
您可以使用限制用户选择其他日期来实现此目的。我使用的是Times Square;自定义日历库。
private void setupCalenderView() {
Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 1);
Date endDate = new DateTime().plusDays(7).toDate(); //End Date
Date startDate = new Date(); //Start Date;
cv_calender.init(startDate , endDate , Locale.ENGLISH)
.withSelectedDate(new Date());
}
对于日期选择,您必须设置此侦听器 - cv_calender.setOnDateSelectedListener(this);
并实施这些方法。
@Override
public void onDateSelected(Date date) {
String selectedDate = new SimpleDateFormat(Your_Date_Format, Locale.ENGLISH).format(date);
}
@Override
public void onDateUnselected(Date date) {
}