How to add days to a date in Java

Make use of Calendar#add(). Here’s a kickoff example.

Calendar dom = Calendar.getInstance();
dom.clear();
dom.set(y, m, d); // Note: month is zero based! Subtract with 1 if needed.
Calendar expire = (Calendar) dom.clone();
expire.add(Calendar.DATE, 100);

If you want more flexibility and less verbose code, I’d recommend JodaTime though.

DateTime dom = new DateTime(y, m, d, 0, 0, 0, 0);
DateTime expire = dom.plusDays(100);

Leave a Comment