How do I change the date to the next in Java?

Asked 1 years ago, Updated 1 years ago, 77 views

I received the date in the form of yyyy-mm-dd. How can I add one more day to this?

java date

2022-09-22 12:17

1 Answers

Stringdt = "2016-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); // add one more day.
dt = sdf.format(c.getTime()); // dt is the day plus one day

You can do it like this.


2022-09-22 12:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.