Possible Duplicate:
Find the number of days in a month in Java
I know these are some ways to do it, but I'm having hard time find information how to do it without passing specified date.
I just want to get number of days in a current month, how do I do that?
Month length() method in Java The length() method is a built-in method of the Month ENUM which is used to get the number of days in this month instance. The number of days in a month can be 28, 30 or 31. Number of days in February in a leap year is 29.
Use the new Date() constructor to get a date object. Call the getMonth() method on the object and add 1 to the result. The getMonth method returns a zero-based month index so adding 1 returns the current month.
Use the getActualMaximum() method to get the last day of the month. int res = cal. getActualMaximum(Calendar. DATE);
Calendar c = Calendar.getInstance(); int monthMaxDays = c.getActualMaximum(Calendar.DAY_OF_MONTH);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With