gpt4 book ai didi

java - 如何使用jsp从月份中排除周末

转载 作者:行者123 更新时间:2023-11-30 11:22:09 26 4
gpt4 key购买 nike

您好,想从月中排除周末,请帮助我。
但这不是从月中排除周末如何排除周末。

 <%     
Calendar cal = Calendar.getInstance(); int day = cal.get(cal.DAY_OF_WEEK);
int days=day-1;
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
Date date1 = df.parse("1/02/2014");
Date date2 = new Date();
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
cal1.setTime(date1);
cal2.setTime(date2);

int numberOfDays = 0;
while (cal1.before(cal2)) {
if ((Calendar.SATURDAY != cal1.get(Calendar.DAY_OF_MONTH))&&(Calendar.SUNDAY != cal1.get(Calendar.DAY_OF_MONTH)))
{
numberOfDays++;
session.setAttribute("numberOfDays",numberOfDays);
cal1.add(Calendar.DATE,1);
}else {
cal1.add(Calendar.DATE,1);
}

}

%>

最佳答案

您需要与 Calendar.DAY_OF_WEEK 而不是 Calendar.DAY_OF_MONTH 进行比较

所以你的条件变成了:

if ((Calendar.SATURDAY != cal1.get(Calendar.DAY_OF_WEEK))
&& (Calendar.SUNDAY != cal1.get(Calendar.DAY_OF_WEEK))) {

关于java - 如何使用jsp从月份中排除周末,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21873749/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com