How can I increment a day to a date in Java?

2

What is the best way to increment a date of type DD/MM/YYYY ?

    
asked by anonymous 27.08.2015 / 17:01

3 answers

2

I suggest using the class Calendar

Date dataTeste = new Date();

Calendar cal = Calendar.getInstance(); 
cal.setTime(dataTeste ); 
cal.add(Calendar.DATE, 1);
dataTeste = cal.getTime();
    
27.08.2015 / 17:07
0

Something like this should work (I'm not an expert in Java):

String dt = "2008-01-01";  // A sua data
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.setTime(sdf.parse(dt));
c.add(Calendar.DATE, 1);  // número de dias a adicionar
dt = sdf.format(c.getTime());  // dt é a sua nova data com mais um dia
    
27.08.2015 / 17:08
0

With java 8 you can do this:

LocalDate hoje = LocalDate.now();
LocalDate amanha = hoje.plusDays(1);
    
03.02.2017 / 11:22