看看在約達時間source code。的Days的daysBetween
方法被定義爲:
public static Days daysBetween(ReadableInstant start, ReadableInstant end) {
int amount = BaseSingleFieldPeriod.between(start, end, DurationFieldType.days());
return Days.days(amount);
}
BaseSingleFieldPeriod
,似天,是不是在約達時間1.2可用,但是,看着它的可用source班1.2開始出現:
protected static int between(ReadableInstant start, ReadableInstant end, DurationFieldType field) {
if (start == null || end == null) {
throw new IllegalArgumentException("ReadableInstant objects must not be null");
}
Chronology chrono = DateTimeUtils.getInstantChronology(start);
int amount = field.getField(chrono).getDifference(end.getMillis(), start.getMillis());
return amount;
}
所有這些類別和方法在Joda Time 1.2中可用,因此兩個實例之間的計算天數將類似於:
public static int daysBetween(ReadableInstant oldDate, ReadableInstant today) {
Chronology chrono = DateTimeUtils.getInstantChronology(oldDate);
int amount = DurationFieldType.days().getField(chrono).getDifference(today.getMillis(), oldDate.getMillis());
return amount;
}
wor K像一個魅力,非常感謝,也解釋如何找到它 – zimZille