maxDays = calendar.getActualMaximum(calendar.DAY_OF_MONTH);
System.out.println(maxDays);

When looking through the javadocs it seems like this would work but it apparently doesn't. Any help on figuring why it doesn't or another way would be appreciated

Calendar myCal = Calendar.getInstance();
System.out.println(myCal.getActualMaximum(Calendar.DATE));

That works, I just tested it on my machine. And according to the Javadoc, DATE is a synonym for DAY_OF_MONTH so day of month should work as well. Although it won't mess anything up, you shouldn't use your instance variable (calendar) to refer to a static field (DAY_OF_MONTH). And of course, that method will return the maximum value for the current month (April) so if you are concerned with a different month you'll have to set the Calendar explicitly first.

Well that code (as is) works. But when i set the month, it prints out 31. So im guessing my attempt at setting didnt work

Calendar myCal = Calendar.getInstance();
		myCal.set(2010,2,1);
		System.out.println(myCal.getActualMaximum(Calendar.DATE));

and the strange thing is when i print out the month using

System.out.println(myCal.get(Calendar.MONTH));

it prints out 2.
Thanks for helping

Ah, fixed it. Apparently according to my code, jan had28 days and feb had 31 lol. Thanks for the help

No problem - mark solved threads as solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.