2つの日付の間の日数を計算する必要があります。以下のコードを使用しています。問題はそれは私を返す2ですが、実際にそれは3月30日6月27日のjuneの違いは3です。あなたはそれが現在の日付と違いを含める必要があります助けてもらえますか?問題は、現在の瞬間にJavaの2つの日付間の日数を計算しない
Date createdDate = new Date();
セットcreatedDate
ことである
public static long getNoOfDaysBtwnDates(String expiryDate) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date expDate = null;
long diff = 0;
long noOfDays = 0;
try {
expDate = formatter.parse(expiryDate);
//logger.info("Expiry Date is " + expDate);
// logger.info(formatter.format(expDate));
Date createdDate = new Date();
diff = expDate.getTime() - createdDate.getTime();
noOfDays = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
long a = TimeUnit.DAYS.toDays(noOfDays);
// logger.info("No of Day after difference are - " + TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS));
System.out.println(a);
System.out.println(noOfDays);
} catch (ParseException e) {
e.printStackTrace();
}
return noOfDays;
}
有効期限は、2016年6月30日であり、現在の日付が2016年6月27日
@AngryJS Checkout私の答え! –