2 つの日付の間の月と日の日付差を見つけたいです。1 つはシステムの現在の日付で、もう 1 つは将来の日付です。
将来の日付は次の形式です。
2014-02-06 21:26
以下のコードを使用して違いを見つけました。
1.
currentCal = Calendar.getInstance();
weddingCal = Calendar.getInstance();
weddingCal.clear();
DateFormat formatterResponseDate = new SimpleDateFormat("yyyy-MM-dd HH:mm");
formatterResponseDate.setTimeZone(TimeZone.getTimeZone("GMT"));
weddingCal.setTime(formatterResponseDate.parse(responseThis.trim()));
long dateDiff = weddingCal.getTimeInMillis() -
currentCal.getTimeInMillis();
long months = dateDiff / (30 * 24 * 60 * 60 * 1000);
long days = (dateDiff % (30 * 24 * 60 * 60 * 1000)) / (24 * 60 * 60 * 1000);
しかし、それは間違った結果をもたらし、月に31日あることもあるので不便だと思います。JODA - Time to find the differenceも使用しましたが、これも役に立ちません。
2.
currentCal = Calendar.getInstance();
startDate = new DateTime(currentCal.get(Calendar.YEAR),
(currentCal.get(Calendar.MONTH)+1),
currentCal.get(Calendar.DAY_OF_MONTH), currentCal.get(Calendar.HOUR),
currentCal.get(Calendar.MINUTE));
weddingCal = Calendar.getInstance();
weddingCal.clear();
weddingCal.setTime(formatterResponseDate.parse(responseThis.trim()));
endDate = new DateTime(weddingCal.get(Calendar.YEAR), (weddingCal.get(Calendar.MONTH)+1),
weddingCal.get(Calendar.DAY_OF_MONTH), weddingCal.get(Calendar.HOUR),
weddingCal.get(Calendar.MINUTE));
Period period = new Period(startDate, endDate);
tvMonth.setText(String.valueOf(period.getMonths()));
tvDays.setText(String.valueOf(period.getDays()));
どちらも機能していません。どうすれば見つけられますか? ありがとう