getReturnDate().MONTH
Isn't doing what you mean. Its value is the value of the Calendar.MONTH
static constant, which is, I suppose, 2 (indeed, you can see it is in the source).
I think you mean
getReturnDate().get(Calendar.MONTH)
Additionally, you shouldn't be calling getReturnDate()
twice: you might get inconsistent dates if you call it twice. Call it once, assign it to a field:
Calendar returnDate = getReturnDate();
// ...
str += "Due date " + (returnDate.get(Calendar.MONTH) + 1) + "/" + returnDate.get(Calendar.DATE);
But in fact a better solution would be not to use these old, effectively-deprecated APIs.
Use a LocalDate
:
LocalDate returnDate = LocalDate.now().plusDays(14);
Then access the returnDate.getMonthValue()
and returnDate.getDayOfMonth()
fields.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…