Can anyone please help.
I am geting current date from Calendar.
I then would like to set a string to a new date by adding number of months..
When i use the following code it works when i add 12 months to date,
But when i try to add 1 month, then next date is January (+2 Months)
When i try to add 3 months, next date is April.
6 months, next date is October 2013 etc….
When trying to add 24, 36 or 48 Months it almost works but is 1 month early.
There doesn’t seem to be a pattern to how the date is changing
//Get Current date and set as text
Calendar c = Calendar.getInstance();
c.add(Calendar.MONTH, Retest); // Months to Date
int day = c.get(Calendar.DATE);
int month = c.get(Calendar.MONTH);
int year = c.get(Calendar.YEAR);
if (month<=9) { MONTH$ = "0"+month ;}
else {MONTH$ = ""+month; } //Set month to MM
NextTest$ = ""+day+"/"+MONTH$+"/"+year; //Put date ints into string DD/MM/YYYY
Toast.makeText(this, "Re-Test Due.. "+NextTest$, Toast.LENGTH_SHORT).show();
According to Java Docs , If any value is passed to Calender’s Add Function, is larger than the Field’s value than it will add the modulo of it . Refer GregorianCalender docs