- 首页 > it技术 > >
java判断当前时间点是否在某个时间点内
private boolean isTimeRange()throws ParseException {
SimpleDateFormat df = new SimpleDateFormat("HH:mm");
Date now = df.parse(df.format(new Date()));
Date begin = df.parse("7:00");
Date end = df.parse("22:00");
Calendar nowTime = Calendar.getInstance();
nowTime.setTime(now);
Calendar beginTime = Calendar.getInstance();
beginTime.setTime(begin);
Calendar endTime = Calendar.getInstance();
endTime.setTime(end);
if (nowTime.before(endTime) && nowTime.after(beginTime)) {
return true;
} else {
return false;
}
}
推荐阅读