3

This code:

Calendar calendar;
calendar = GregorianCalendar.getInstance();
calendar.set(year, month, day);
week_day = calendar.get(Calendar.DAY_OF_WEEK);

returns wrong value.

For example

  • year=2013, month=3, day=31

returns the same value of

  • year=2013, month=4, day=1.

How I can do this correctly ?

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243

1 Answers1

7

In Java, months start from 0.

Month 3 day 31 is April 31, that does not exist, then it will be shifted to May 1,

Month 4 day 1 is May 1, the same day as above.

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243