public classCheckClosingTimeUtil {/*** 校验当前时间是否在规定时间内
*@parambusinessHours 某商店营业时间或者是别的
*@returntrue:在规定时间 false:未在规定时间*/
public static booleancheckClosingTime(String businessHours){if(StringUtils.isNotBlank(businessHours)){
BulidBusinessHours bulidBusinessHours= newBulidBusinessHours(businessHours).invoke();long start =bulidBusinessHours.getStart();long end =bulidBusinessHours.getEnd();
Calendar currentTime=Calendar.getInstance();long current =currentTime.getTimeInMillis();if(current>start && current
}else{return false;
}
}return false;
}/*** 校验当前时间是否在规定时间内2
*@parambusinessHours 某商店营业时间或者是别的
*@paramcurrent 单位;当前时间 - 毫秒级
*@return
*/
public static boolean checkClosingTime(String businessHours,longcurrent){if(StringUtils.isNotBlank(businessHours)){
BulidBusinessHours bulidBusinessHours= newBulidBusinessHours(businessHours).invoke();long start =bulidBusinessHours.getStart();long end =bulidBusinessHours.getEnd();if(current>start && current
}else{return false;
}
}return false;
}private static classBulidBusinessHours {privateString businessHours;private longstart;private longend;publicBulidBusinessHours(String businessHours) {this.businessHours =businessHours;
}public longgetStart() {returnstart;
}public longgetEnd() {returnend;
}publicBulidBusinessHours invoke() {
List businessTime = Arrays.asList(businessHours.split("-"));
List startBusinessTime = Arrays.asList(businessTime.get(0).split(":"));
List startTime = startBusinessTime.stream().map(e ->Integer.valueOf(e)).collect(Collectors.toList());
List endBusinessTime = Arrays.asList(businessTime.get(1).split(":"));
List endTime = endBusinessTime.stream().map(e ->Integer.valueOf(e)).collect(Collectors.toList());
Calendar drugstoreStartTime=Calendar.getInstance();
drugstoreStartTime.set(Calendar.HOUR_OF_DAY, startTime.get(0));
drugstoreStartTime.set(Calendar.MINUTE, startTime.get(1));
drugstoreStartTime.set(Calendar.SECOND,0);
start=drugstoreStartTime.getTimeInMillis();
Calendar drugstoreEndTime=Calendar.getInstance();
drugstoreEndTime.set(Calendar.HOUR_OF_DAY, endTime.get(0));
drugstoreEndTime.set(Calendar.MINUTE, endTime.get(1));
drugstoreEndTime.set(Calendar.SECOND,0);
end=drugstoreEndTime.getTimeInMillis();return this;
}
}
}