- Create a Calendar object and set it to the first of the next month (for example, to 1 February 2006). - Subtract 1 day off the calendar: cal.add(Calendar.DATE, -1); - Get the day number of the calendar: int numberOfDaysInJanuary = cal.get(Calendar.DATE);
Indeed, getMaximum() should return 31. It's getActualMaximum() that you want here.
"I'm not back." - Bill Harding, Twister
Joined: Sep 21, 2005
Thanks a lot to you all for your instant replies. I have found the solution for that as follows :
SimpleDateFormat df = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss"); String sdate1 = "1-1-2004 00:00:00"; Date date1 = df.parse(sdate1); Calendar cal1 = Calendar.getInstance(); cal1.setTime(date1);
maximum1 = cal1.getActualMaximum(cal1.DAY_OF_MONTH); // This will return the maximum.
If any queries then feel free to ask.
Thanks Regards Gaurav
Joined: Oct 07, 2005
Originally posted by Jim Yingst: Indeed, getMaximum() should return 31. It's getActualMaximum() that you want here.
Actually, I should've been clearer about this. I had been perusing this API doc with an intent to get the answer to this question sometime ago, and I wasn't sure which of the getXMaximum() methods would do the job, and hadn't tried. Glad we now have a try and its results.