I'm working with a date in this format: yyyy-mm-dd
.
How can I increment this date by one day?
time. ZonedDateTime zdtMonthLater = zdt. plusMonths( 1 );
Use the add() method of the calendar class to add days to the date. The add method() takes two parameter, i.e., calendar field and amount of time that needs to be added. Get the new date from the calendar and set the format of the SimpleDateFormat class to show the calculated new date on the screen.
DateTime yesterday = new DateTime(). minusDays(1);
Date today = new Date(); Date tomorrow = new Date(today. getTime() + (1000 * 60 * 60 * 24));
Something like this should do the trick:
String dt = "2008-01-01"; // Start date SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar c = Calendar.getInstance(); c.setTime(sdf.parse(dt)); c.add(Calendar.DATE, 1); // number of days to add dt = sdf.format(c.getTime()); // dt is now the new date
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With