我正在使用Joda Time来获取daysBetween()两天,但它在2天之间没有返回任何天数,并且数据的前缀和后缀正在添加" P" &安培; " d"和/" P" &安培; " Y"同一年之间的年份将在monthBetween(),yearsBetween(),hoursBetween(),minutesBetween()和secondsBetween()之间。
如何获取没有前缀和后缀字符串的数据?
DateTime start = new DateTime(2004, 12, 25, 0, 0, 0, 0);
DateTime end = new DateTime(2006, 1, 1, 0, 0, 0, 0);
// able to calculate whole days between two dates easily
Days days = Days.daysBetween(start, end);
// able to calculate whole months between two dates easily
Months months = Months.monthsBetween(start, end);
答案 0 :(得分:1)
前缀/后缀只是持续时间的字符串表示,它基于ISO8601,如这些类的toString
javadoc中所述。
如果您只想要天数,可以使用:
int days = Days.daysBetween(start, end).getDays();
同样,Months
有getMonths
方法。