0
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?

curiousity
  • 4,703
  • 8
  • 39
  • 59
  • 1
    possible duplicate of [How can I increment a date by one day in Java?](http://stackoverflow.com/questions/428918/how-can-i-increment-a-date-by-one-day-in-java) – Mike Argyriou May 28 '14 at 11:40
  • Maybe this answer can help you if you are using Java 8 or newer: http://stackoverflow.com/a/23910924/1115554 – micha May 28 '14 at 11:56

1 Answers1

1

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
Hirak
  • 3,601
  • 1
  • 22
  • 33