Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the number of days in the current month in Java [duplicate]

Tags:

java

datetime

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?

like image 974
Jacek Kwiecień Avatar asked Jan 11 '12 15:01

Jacek Kwiecień


People also ask

How to get the number of days in month in java?

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.

How can I get current month?

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.

Is last day of month Java?

Use the getActualMaximum() method to get the last day of the month. int res = cal. getActualMaximum(Calendar. DATE);


1 Answers

Calendar c = Calendar.getInstance(); int monthMaxDays = c.getActualMaximum(Calendar.DAY_OF_MONTH); 
like image 148
4ndrew Avatar answered Oct 18 '22 19:10

4ndrew