I am trying to make a method where you can enter the arguments of, the current month and the amount of months you want to trace back, and convert all of this into days. For example, if the current month was January and I wanted convert the last 5 months into days the answer would be 153. I have the following information for one to use.
private Calendar cal;
private int currentMonth;
private final int JANUARY = 31;
private final int FEBRUARY = 28;
private final int MARCH = 31;
private final int APRIL = 30;
private final int MAY = 31;
private final int JUNE = 30;
private final int JULY = 31;
private final int AUGUST = 31;
private final int SEPTEMBER = 30;
private final int OCTOBER = 31;
private final int NOVEMBER = 30;
private final int DECEMBER = 31;
public Constructor(){
cal = new GregorianCalendar();
currentMonth = cal.get(Calendar.MONTH);
}
private int convertMonthsToDays(int currentMonth, int months){
int days;
return days;
}
Use this code for what you want
use calendar.add(Calendar.MONTH, -1); for Month back.
use calendar.add(Calendar.MONTH, 1); for month forward.