Joda Time daysBetween() returns 字符串前缀 "P" 和后缀 "D"
Joda Time daysBetween() returns string prefix "P" and suffix "D"
我正在使用 Joda Time 获取 daysBetween() 两天,但它返回 2 天之间的天数,并且数据的前缀和后缀正在添加 "P" & "D" 天between and "P" & "Y" for years between the same will be in monthsBetween(), yearsBetween(), hoursBetween(), minutesBetween() and 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);
prefix/suffix 只是持续时间的字符串表示,它基于 ISO8601,如 类.
的 toString
javadoc 中所述
如果你只是想要天数,你可以使用:
int days = Days.daysBetween(start, end).getDays();
同样,Months
有一个getMonths
方法。
我正在使用 Joda Time 获取 daysBetween() 两天,但它返回 2 天之间的天数,并且数据的前缀和后缀正在添加 "P" & "D" 天between and "P" & "Y" for years between the same will be in monthsBetween(), yearsBetween(), hoursBetween(), minutesBetween() and 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);
prefix/suffix 只是持续时间的字符串表示,它基于 ISO8601,如 类.
的toString
javadoc 中所述
如果你只是想要天数,你可以使用:
int days = Days.daysBetween(start, end).getDays();
同样,Months
有一个getMonths
方法。