I have a date in the format dd-MM-yyyy in an EditText with InputType="date" called "start".
I want to get this date, put its contents in the variable Date called "inifer" and on this date add an integer variable called "diafer" and subtract 1 and play in the variable "terfer".
My commands are:
String datastr = inicio.getText().toString();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date inifer = new Date();
try
{
inifer = dateFormat.parse(datastr);
}
catch (ParseException e)
{
e.printStackTrace();
}
Log.i("Data de início", dateFormat.format(inifer));
int diafer = Integer.parseInt(diasfer.getText().toString());
Log.i("dias de férias", String.valueOf(diafer));
Calendar c = Calendar.getInstance();
Date terfer = inifer;
c.setTime(terfer);
c.add(c.DATE, diafer - 1);
terfer.setTime(c.DATE);
int mester = c.MONTH;
int diater = c.DAY_OF_MONTH;
Log.i("mês de término férias", String.valueOf(mester));
Log.i("dia de término férias", String.valueOf(diater));
The Logs show the correct content except the last two.
With the date of 10/05/2016 and 30 days of vacation, they show month 2 and day 5, when it should be month 6 and day 8, as 29 days after 10/05/2016 is day 08 / 06/2016.
Where did I go wrong?