Java is the last day of next month
•
Java
I have a variable of nowdate type. I want to set the variable nextdate to include the last day of the next month
For example: nowdate = April 16, 2013
So nextdate will include May 31, 2013
How can I do this?
Solution
attempt
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);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
