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?

1 Answer

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.

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)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.5k answers

500 comments

108k users

Browse Categories

...