Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (3.5k points)
I'm working with a date in this format: yyyy-mm-dd.

How can I increment this date by one day?

2 Answers

0 votes
by (46k points)

This is very simple, just use a syntax like this one:

String dt = "2019-07-12";  // 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

You can read about it here.

0 votes
ago by (1.8k points)

We can increment date by one day in java using 2 different approaches:

  1. By using java.util.calendar class but this approach is considered the older approach.
  2. By java.time package which is a new approach and it was introduced in Java 8 and this approach is more readable and provides better support for data & time manipulations.

Related questions

0 votes
1 answer
asked Sep 21, 2019 in Java by Shubham (3.9k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 4, 2019 in SQL by Tech4ever (20.3k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...