/**
* 判断目标时间是否在给定时间区间
* @param startTime 给定的起始时间
* @param endTime 给定的结束时间
* @param targetTime 目标时间
* @param format 格式化字符串
* @return 是否在区间范围内
*/
public boolean inTimeRange(String startTime,String endTime,String targetTime,String format){
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
Calendar calendar = Calendar.getInstance();
calendar.setTime(simpleDateFormat.parse(startTime));
Date start = calendar.getTime();
calendar.setTime(simpleDateFormat.parse(endTime));
Date end = calendar.getTime();
calendar.setTime(simpleDateFormat.parse(targetTime));
Date target = calendar.getTime();
if (target.before(end)&&target.after(start)){
return true;
}
} catch (ParseException e) {
return false;
}
return false;
}
判断给定时间是否在目标时间段内
最新推荐文章于 2023-03-14 10:56:46 发布
7756

被折叠的 条评论
为什么被折叠?



