/**
* 判断是否满足时间内
* @param xianZhiTime限制时间
* @return
*/
public static boolean cutTime(String xianZhiTime) {
String[] args = xianZhiTime.split("-");
SimpleDateFormat sim = new SimpleDateFormat("HH:mm");
String nowTime=sim.format(new Date());
try {
long now = sim.parse(nowTime).getTime();
long start = sim.parse(args[0]).getTime();
long end = sim.parse(args[1]).getTime();
if (args[1].equals("00:00")) {//翻译小时
args[1] = "24:00";
}
if (end < start) {
if (now >= end && now < start) {
return false;
} else {
return true;
}
}
else {
if (now >= start && now < end) {
return true;
} else {
return false;
}
}
} catch (ParseException e) {
e.printStackTrace();
System.out.println("传入的时间参数异常!");
return false;
}
}
public static void main(String[] args) {
System.out.println(cutTime("17:00-20:00"));;
}