Stack Overflow archive
1 scoreaccepted

How can i increment my date by 1

score
1
question views
390
license
CC BY-SA 3.0

The code should be working fine as long as dt and days are correct. This gave me 12-18-2014:

java
String dt = "12-17-2014"; // Start date
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-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());

Originally posted on Stack Overflow. Public user contributions are licensed under Creative Commons Attribution-ShareAlike.