I have a date String newDate = "31.05.2001"
which I should increase by 1 day.
I tried the following code:
String dateToIncr = "31.12.2001"; String dt=""; SimpleDateFormat sdf = new SimpleDateFormat("dd.mm.yyyy"); Calendar c = Calendar.getInstance(); try { c.setTime(sdf.parse(dateToIncr)); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } c.add(Calendar.DAY_OF_MONTH, 1); // number of days to add dt = sdf.format(c.getTime()); System.out.println("final date now : " + dt);
But with the help of this code, just to add a DAY, ie the output of 05/31/2001 will be 05/05/2001, keeping the month and year unchanged! Please help me with this.
I also tried
c.roll(Calendar.DATE, 1); // number of days to add
source share