My input string date is as below:
String date = "1/13/2012";
I am getting the month as below:
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
Date convertedDate = dateFormat.parse(date);
String month = new SimpleDateFormat("MM").format(convertedDate);
But how do I get the last calendar day of the month in a given String date?
E.g.: for a String "1/13/2012" the output must be "1/31/2012".
Java 8 and above.
By using
convertedDate.getMonth().length(convertedDate.isLeapYear())whereconvertedDateis an instance ofLocalDate.Java 7 and below.
By using
getActualMaximummethod ofjava.util.Calendar: