我尝试将某个日期与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
2012年2012年
应该得到相同的结果,不是吗?
答案 0 :(得分:1)
这两个代码都可以正常工作
DateTime dt = new DateTime();
dt = dt.withWeekOfWeekyear(29);
dt = dt.withWeekyear(2011);
DateMidnight dt2 = new DateMidnight().withWeekOfWeekyear(29).withYear(2011);
答案 1 :(得分:0)
withWeekyear
与withWeekOfWeekyear
不同。我不是100%确定withWeekyear
代替的是什么,我想如果你的意思是2012年的第37周,你应该使用withWeekOfWeekyear
代替。
答案 2 :(得分: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 */
现在你设定日期!以这种方式设置第二个并比较它们。