请我想计算两个日期之间的时间段,我搜索并没有找到我需要的。我有这个代码:
public int getNbjours() {
DateTime dt1 = new DateTime(date1);
DateTime dt2 = new DateTime(date2);
Period period = new Period(dt1, dt2);
nbjours=period.getDays();
return nbjours;
}
public int getNbmois() {
DateTime dt1 = new DateTime(date1);
DateTime dt2 = new DateTime(date2);
Period period = new Period(dt1, dt2);
nbmois=period.getMonths();
return nbmois;
}
问题是有时它会给我错误的结果,例如:
From 2013-05-27 To 2013-06-28 => 1 day and 1 months (it's right here)
From 2013-05-27 To 2013-07-26 => 1 it gives me also 1 day and 1 months and that's false !
From 2013-04-01 To 2013-09-04 => 3 days and 5 months (here it's right)
在那个错误的值中,通常27/05
是26/07
真的1 month
但不仅仅是1 day
,29 days
请问为什么它给了我错误的值?