String format = "yyyy-MM-dd hh:mm:ss";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
Date date = new Date(System.currentTimeMillis());
String today = simpleDateFormat.format(date);
Date nowTime = simpleDateFormat.parse(today);
Date startDate = simpleDateFormat.parse(“日期”);
Date endDate = simpleDateFormat.parse(“日期”);
/**
* 判断当前时间是否在[startTime, endTime]区间,注意时间格式要一致
*
* @param nowTime 当前时间
* @param startTime 开始时间
* @param endTime 结束时间
* @return
*/
public static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) {
if (nowTime.getTime() == startTime.getTime()
|| nowTime.getTime() == endTime.getTime()) {
return true;
}
Calendar date = Calendar.getInstance();
date.setTime(nowTime);
Calendar begin = Calendar.getInstance();
begin.setTime(startTime);
Calendar end = Calendar.getInstance();
end.setTime(endTime);
if (date.after(begin) && date.before(end)) {
return true;
} else {
return false;
}
}