Mister M Mister M - 4 months ago 10
Java Question

how to add a single day to "dd/mm" format in java

I have a date in

dd/mm
(15/07)
format, I need to add a single day to this date, so it becomes
16/07
.

How can I do this in the easiest way in java?

Answer

You can use Calendar.

String dt = "15-07-2016";  
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
Calendar c = Calendar.getInstance();
c.setTime(sdf.parse(dt));
c.add(Calendar.DATE, 1);  // number of days to add
dt = sdf.format(c.getTime());  
Comments