0

我尝试将某个日期与 jodaTime 进行比较,我使用周和年来比较日期

DateMidnight endDate01 = new DateMidnight().withYear(2012).withWeekyear(37);
DateMidnight endDate02 = new DateMidnight().withYear(2012).withWeekyear(38);


endDate01.isBefore(endDate02); //return false

我不明白为什么 endDate01 看起来比 endDate02 更大。

也许是一个错误?

DateMidnight endDate01 = new DateMidnight();

endDate01.withYearOfEra(o1.getEndYearPeriod());
endDate01.withWeekOfWeekyear(o1.getEndWeekPeriod());

System.out.println(o1.getEndWeekPeriod() + " " + o1.getEndYearPeriod());
System.out.println(endDate01.getWeekOfWeekyear() + " " + endDate01.getYearOfEra());

我明白了

37 2012

16 2012

应该得到相同的结果,不是吗?

4

3 回答 3

1

这两个代码都可以正常工作

DateTime dt = new DateTime(); 
dt = dt.withWeekOfWeekyear(29); 
dt = dt.withWeekyear(2011);

DateMidnight dt2 = new DateMidnight().withWeekOfWeekyear(29).withYear(2011);
于 2012-04-21T11:16:00.670 回答
0
DateTime firstDate = new DateTime();
firstDate.withWeekyear(2012) /* represents the 2012 with number of weeks in it (I thing the algorith is the difference between first week in 1970) */
firstDate.withWeekOfWeekyear(29) /* now you have the 29th week of 2012 */
firstDate.withDayOfWeek(1) /* now you have 29th week of 2012 and Monday */

现在你设置日期!以这种方式设置第二个并比较它们。

于 2012-04-21T11:28:31.303 回答
0

withWeekyear不一样withWeekOfWeekyear。我不是 100% 确定用什么withWeekyear代替,我认为如果你的意思是 2012 年的第 37 周,你应该withWeekOfWeekyear改用。

于 2012-04-20T20:10:15.690 回答