想先获取当前时间,然后判断当前时间是否为周一到周五工作日的非工作日间(工作时间为8:30-17:00),C币不多。就大神帮忙
//根据开始结束时间计算工作小时数(开始结束时间是同一天)
public static Double getOneDayWorkTimeHours(Date begin, Date end){
Double xss = 0.0;
if(begin.compareTo(end) != -1){
logger.warn("我填写的开始时间比结束时间还晚");
xss = 0.0;
return xss;
};
Double oneHour = 60.0;
DateTime startdt = new DateTime(begin);
DateTime enddt = new DateTime(end);
/*下面这些是固定的上班时间*/
//早上上班时间 8:30
Date beginworkdate = (Date) begin.clone();
beginworkdate = DateUtils.setHours(beginworkdate, 8);
beginworkdate = DateUtils.setMinutes(beginworkdate, 30);
DateTime workbegin = new DateTime(beginworkdate);
//上午下班时间 12:00
Date beginlaunchdate = (Date) begin.clone();
beginlaunchdate = DateUtils.setHours(beginlaunchdate, 12);
beginlaunchdate = DateUtils.setMinutes(beginlaunchdate, 0);
DateTime launchbegin = new DateTime(beginlaunchdate);
//下午上班时间 14:00
Date endlaunchdate = (Date) begin.clone();
endlaunchdate = DateUtils.setHours(endlaunchdate, 14);
endlaunchdate = DateUtils.setMinutes(endlaunchdate, 0);
DateTime launchend = new DateTime(endlaunchdate);
//下午下班时间 17:30
Date workenddate = (Date) end.clone();
workenddate = DateUtils.setHours(workenddate, 17);
workenddate = DateUtils.setMinutes(workenddate, 30);
DateTime workend = new DateTime(workenddate);
/*到这里规定动作写完*/
//2.减去周六周日及节假日 -----选择在节假日补休的人,肯定是测试吧---doglus
SimpleDateFormat format = new SimpleDateFormat(com.common.StringCommon.DATEFORMATE);
if (startdt.isBefore(workbegin) || startdt.isEqual(workbegin)) {//1.开始时间早于8:30 设置开始时间为8:30
//1.1结束时间在12:00之前 不用扣掉午休时间
if (enddt.isBefore(launchbegin)||enddt.isEqual(launchbegin)) {
int minits = Minutes.minutesBetween(workbegin, enddt).getMinutes();
xss = minits/oneHour;
logger.info("补休时间为上午时间段-补休小时为: " + xss);
}else if(enddt.isBefore(launchend)||enddt.isEqual(launchend)){
//1.2 结束时间在下午上班之前,就是只上一上午整班
int minits = Minutes.minutesBetween(workbegin, launchbegin).getMinutes();
xss = (double) minits/oneHour;
logger.info("存在午休时间段(扣午休时间)-补休小时为: " + xss);
}else if(enddt.isBefore(workend)){
//1.3 结束时间在14:00之后 下班之前
int minits = Minutes.minutesBetween(launchend, enddt).getMinutes();
logger.info("上午加下午扣午休2小时-补休小时为: " + (minits/oneHour + 3.5));
xss = (double) minits/oneHour + 3.5;
}else{
//1.4 结束时间在下班之后
int minits = Minutes.minutesBetween(workbegin, workend).getMinutes();
logger.info("实际上就是7小时--: " + (minits/oneHour - 2));
xss = minits/oneHour - 2;
};
}else if(startdt.isBefore(launchbegin)){//2.开始时间在8:30和12:00之间
//2.1结束时间在12:00之前 不用扣掉午休时间
if (enddt.isBefore(launchbegin)) {
int minits = Minutes.minutesBetween(startdt, enddt).getMinutes();
xss = minits/oneHour;
logger.info("上午时间段-补休小时为: " + xss);
}else if(enddt.isBefore(launchend)){
//2.2 结束时间在下午上班之前
int minits = Minutes.minutesBetween(startdt, launchbegin).getMinutes();
xss = minits/oneHour;
logger.info("上午时间段,结束时间存在午休时间-补休小时为: " + xss);
}else if(enddt.isBefore(workend)){
//2.3 结束时间在14:00之后 下班之前
int minits = Minutes.minutesBetween(startdt, enddt).getMinutes();
xss = minits/oneHour-2;
logger.info("上午加下午扣2小时补休时间: " + xss);
}else{
//2.4 结束时间在下班之后
int minits = Minutes.minutesBetween(startdt, workend).getMinutes();
xss = minits/oneHour - 2;
logger.info("上午加下午(全部)扣2小时午休: " + xss);
};
}else if(startdt.isBefore(launchend)){
//3.开始时间在12:00和14:00之间
if(enddt.isBefore(workend)){
//3.1结束时间在14:00之后 下班之前
int minits = Minutes.minutesBetween(launchend, enddt).getMinutes();
xss = minits/oneHour;
logger.info("下午补休-补休小时为: " + xss);
}else if (enddt.isAfter(workend)) {
//3.2 结束时间在下班之后
int minits = Minutes.minutesBetween(launchend, workend).getMinutes();
xss = minits/oneHour;
logger.info("整整一个下午实际上是3: " + xss);
}else{
//3.3 结束时间在下午上班之前
logger.warn("没有在正常时间补休休假时间为0");
xss = 0.0;
};
}else if(startdt.isBefore(workend)){
//4.开始时间在午休之后下班之间
//4.1结束时间也在下班之前
if (enddt.isBefore(workend) || enddt.isEqual(workend)) {
int minits = Minutes.minutesBetween(startdt, enddt).getMinutes();
xss = minits/oneHour;
logger.info("补休时间为下午上班时间-补休小时数为: " + xss);
}else if(enddt.isAfter(workend)){
//4.2 结束时间在下班之后
int minits = Minutes.minutesBetween(startdt, workend).getMinutes();
xss = minits/oneHour;
logger.info("补休时间为下午上班时间(扣下班之后时间)-补休小时数为: " + minits/oneHour);
}else{
//4.3 其它情况都非法
logger.error("输入时间段非法,请重新输入 。开始时间: "+ startdt.toString() +" 结束时间:" + enddt.toString());
xss = 0.0;
};
}
return xss;
};
有个simpledateformate类,里面好像有判断周几的方法
var d=new Date();
var xq=d.getDay(),h=d.getHours(),m=d.getMinites(),sj=(h<10?'0':'')+h+':'+(m<10?'0':'')+m;
if(xq>=1&&xq<=5 &&sj>='08:30'&&sj<='17:00')alert('工作日')
hql ="from 表 as b where DATE_FORMAT(modify_date,'%Y%m%d')=DATE_FORMAT(now(),'%Y%m%d') order by(b.income+b.money) DESC limit 0,15 "; 日
hql ="from 表 as b where WEEK(modify_date)=WEEK(NOW()) AND YEAR(modify_date) = YEAR(NOW())) order by(b.income+b.money) DESC limit 0,15 "; //周 这是我查询的例字希望对你有用
获取当前时间的星期和时间,然后你想怎么判断就怎么判断了
Java中可以判断,使用localdate获取,方法getDayOfWeek
可以试着用calender,或者楼上的simpledateformat也可以