java判断一个日期是否为工作日
程序员文章站
2022-05-17 21:37:18
...
java判断一个日期是否为工作日
/**
* @Author :feiyang
* @Date :Created in 7:47 PM 2019/12/3
*/
public class LocalDateTimeUtil {
/**
* 判断指定时间是否在工作时间内
* @author feiyang
* @param seconds
* @return java.lang.Boolean
* @date 2020/1/13
* @throws
*/
public static Boolean isWorkDuration(Long seconds) {
LocalDateTime localDateTime = LocalDateTime.ofEpochSecond(seconds,0,ZoneOffset.ofHours(8));
DayOfWeek dayOfWeek = localDateTime.getDayOfWeek();
if (DayOfWeek.SATURDAY == dayOfWeek || DayOfWeek.SUNDAY == dayOfWeek) {
return false;
}
Long startAm = convertDateToLongSecond(localDateTime.withHour(9).withMinute(0).withSecond(0).withNano(0));
Long endAm = convertDateToLongSecond(localDateTime.withHour(12).withMinute(0).withSecond(0).withNano(0));
if (seconds >= startAm && seconds <= endAm) {
return true;
}
Long startPm = convertDateToLongSecond(localDateTime.withHour(13).withMinute(0).withSecond(0).withNano(0));
Long endPm = convertDateToLongSecond(localDateTime.withHour(18).withMinute(0).withSecond(0).withNano(0));
if (seconds >= startPm && seconds <= endPm) {
return true;
}
return false;
}
}
上一篇: Java通过月份获取当月工作日
下一篇: java 时间+X工作日