Question

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.

Was it helpful?

Solution

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top