gpt4 book ai didi

java - Joda-Time - 天数不增加

转载 作者:行者123 更新时间:2023-11-29 07:45:38 30 4
gpt4 key购买 nike

这是一个学校项目。

代码如下:

// get the remaining available hours
public int getAvailableHours(Subject sub) {

DateTime dt = new DateTime();
int hours = 0;

int mondays = 0;
int tuesdays = 0;
int wednesdays = 0;
int thursdays = 0;
int fridays = 0;
int saturdays = 0;
int sundays = 0;

if(sub != null) {
if(!sub.getExamDate().isBefore(dt)) {
int days = Days.daysBetween(dt, sub.getExamDate()).getDays();

// DEBUGGING - take out
System.out.println(days);
System.out.println(dt);
System.out.println(sub.getExamDate());

DateTime day = new DateTime();
for(int i = 1; i < days; i++) {
day.plusDays(i);

// DEBUGGING - take out
System.out.println(day.dayOfWeek().getAsText());
System.out.println(day.dayOfMonth().getAsText());

switch(day.dayOfWeek().getAsText()) {
case "Monday":
mondays++;
break;
case "Tuesday":
tuesdays++;
break;
case "Wednesday":
wednesdays++;
break;
case "Thursday":
thursdays++;
break;
case "Friday":
fridays++;
break;
case "Saturday":
saturdays++;
break;
case "Sunday":
sundays++;
break;
default:

break;
}
}
hours = (mondays * hoursOnMonday) + (tuesdays * hoursOnTuesday) +
(wednesdays * hoursOnWednesday) + (thursdays * hoursOnThursday)
+ (fridays * hoursOnFriday) + (saturdays * hoursOnSaturday)
+ (sundays * hoursOnSunday);
}
}

return hours;
}

我想做的是创建一个学习时间表调度程序。我的程序中有一部分允许用户输入他们每天想学习多长时间。所以我在上面做的是遍历有多少天,看看每天有多少天发生(所以,从现在到该科目的考试日期之间有多少个星期一、星期二等),这样我就可以计算出有多少天用户必须学习的总小时数。

但是现在,我尝试遍历它,它总是返回“星期三”,它没有递增。今天,在南非,是 10 月 1 日星期三,但该应用程序现在似乎确实增加了这一天,以意识到它正在查看 10 月 2 日星期四(明天)。我认为问题出在这一行:day.plusDays(i);,但我不知道解决它的方法。

最佳答案

它是不可变的实例,所以你必须把它抓回来

day = day.plusDays(i);

This datetime instance is immutable and unaffected by this method call. from doc

关于java - Joda-Time - 天数不增加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26135440/

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