This content has been marked as final. Show 5 replies
You're not making sense. The number of days in a month is an integer. It doesn't have a "mm/dd/yyyy" format.
Are you trying to say that you're trying to get a formatted date string representing the last day of a month?
In that case, set the date in the calendar to the last day of the month, get a Date object from the Calendar, and then pass the Date object to a java.text.SimpleDateFormat.
thanks for your suggestion.
can you please send me the sample code
No. What part of what I said didn't you understand?
thanks , I got the solution;
but I wonder why month is giving me 9 instead of 10.
DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy"); int month =calendar.get(calendar.MONTH); int year = calendar.get(calendar.YEAR); int totalNumberOfDaysInTheCurrentMonth =calendar.getActualMaximum(calendar.DAY_OF_MONTH); calendar.set(year,month,totalNumberOfDaysInTheCurrentMonth); Date d =calendar.getTime(); System.out.println("krishna"+formatter.format(d));
Months are zero-indexed. January is month number zero.