I have variable nowDate type of Date and I want set variable nextDate contains last day in next month.
For example: nowDate = 2013-04-16
So nextDate will contains 2013-05-31
How can I do that?
Try
private static Date getNextDate(Date nowDate) {
Calendar c = Calendar.getInstance();
c.setTime(nowDate);
c.add(Calendar.MONTH, 1);
c.set(Calendar.DATE, c.getMaximum(Calendar.DATE));
Date nextDate = c.getTime();
return nextDate;
}
Usage:
Date nowDate = new Date();
Date nextDate = getNextDate(nowDate);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With