我想兩個日期之間獲得剩餘的年,月,和天天: 所以我已經使用約達時間這樣做:剩餘的年,月,使用約達時間(安卓)
DateTime endDate = new DateTime(2018,12,25,0,0);
DateTime startDate = new DateTime();
Period period = new Period(startDate,endDate,PeriodType.yearMonthDay());
PeriodFormatter formatter = new PeriodFormatterBuilder().appendYears().appendSuffix(" Year ").
appendMonths().appendSuffix(" Month ").appendDays().appendSuffix(" Day ").appendHours()..toFormatter();
String time = formatter.print(period);
這給我的字符串時間:2年4個月22日
但是,我希望剩餘年數,月份,天數的每個數字的整數值。 所以,取而代之的「2年4月22日」,我想設置我的變量:
int year = 2
int month = 4
int day = 22
有什麼辦法來獲取這些值分別,而不是獲得一個字符串?非常感謝! :)
閱讀[文檔](http://joda-time.sourceforge.net/apidocs/org/joda/time/Period.html)!有getter方法。 – Andreas