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.
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.
PS: getMonth
is really not a good name for a variable denoting a month. It's not a getter is it?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.