字符串时间转Date
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date1 = format.parse("2021-08-01 00:00:00");
} catch (Exception e) {
e.printStackTrace();
}
判断时间是否在有效时间内
private boolean belongCalendar(Date nowTime, Date beginTime ,Date endTime) {
Calendar date = Calendar.getInstance();
date.setTime(nowTime);
Calendar begin = Calendar.getInstance();
begin.setTime(beginTime);
Calendar end = Calendar.getInstance();
begin.setTime(endTime);
return date.after(begin) && date.before(end);
}