Problemas con la FECHA del calendario

Date toDate = new Date(114, 5, 30);    
Calendar calendar = Calendar.getInstance();
            Calendar calendarTo = Calendar.getInstance();
            calendar.setTime(toDate);
            calendarTo.setTime(toDate);
            calendarTo.add(Calendar.DATE, 1);

this is how I initialize calendars and I am trying to put NEXT day in calendarTo but when I getting calendar.Date it is equal to calendarTo.DATE and is equal to 5.. why? And how I could finally increment this DATE value?

preguntado el 28 de mayo de 14 a las 12:05

Maybe this answer can help you if you are using Java 8 or newer: stackoverflow.com/a/23910924/1115554 -

1 Respuestas

What you are getting is the default value of DATE in Calendar class. Which is 5

public final static int DATE = 5;

But when I print the dates from your code, looks like it is fine.

Date toDate = new Date(114, 5, 30);    
    Calendar calendar = Calendar.getInstance();
                Calendar calendarTo = Calendar.getInstance();
                calendar.setTime(toDate);
                calendarTo.setTime(toDate);
                calendarTo.add(Calendar.DATE, 1);

                System.out.println(toDate);//Mon Jun 30 00:00:00 IST 2014
                System.out.println(calendarTo.getTime());//Tue Jul 01 00:00:00 IST 2014

contestado el 28 de mayo de 14 a las 12:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.