0

I have an excel file with dates in this format 31/08/13. What I need to do is to calculate a monthly interest based on the dates. The problem is that I need to know the number of days of the month.

Here is how I'm getting the month name inside of a loop:

getMonth = new DateFormatSymbols().getMonths()[currentMonth-1]; //february

where getMonth is a string and currentMonth is the month number.

Now I'm trying to get the number of days with:

Calendar mycal = new GregorianCalendar(1999, Calendar.FEBRUARY, 1);
int daysInMonth = mycal.getActualMaximum(Calendar.DAY_OF_MONTH); // 28

My problem is that I can not(and its logic) replace FEBRUARY with the getMonth string, which is containing the month's name.

I know there is a much easier way to achieve it, but I'm really not able to spot it.

SpringLearner
  • 13,738
  • 20
  • 78
  • 116
Slim
  • 1,708
  • 5
  • 37
  • 60

1 Answers1

4

The type of Calendar.FEBRUARY and other constants in Calendar class is int. You should change getMonth to an int, to make the constructor compile. Or, directly use currentMonth - 1 in the constructor parameter, and by pass the creation of getMonth variable.

P.S: getMonth is really not a good name for a variable denoting a month. It's not a getter is it?

Rohit Jain
  • 209,639
  • 45
  • 409
  • 525