0

With this code, I get the days that make up a given month, but if I want to get if the month starts on a Monday or Tuesday, as I do?

Calendar mycal = new GregorianCalendar(anni, Calendar.FEBRUARY, 1);
int giorni = mycal.getActualMaximum(Calendar.DAY_OF_MONTH); // 28
CL.
  • 173,858
  • 17
  • 217
  • 259
user3461181
  • 43
  • 1
  • 1
  • 5
  • Try this.. http://stackoverflow.com/questions/8997228/how-to-get-the-first-day-of-a-month – Sush Apr 15 '14 at 15:56

1 Answers1

0

Try:

int anni = 2014;
Calendar mycal = new GregorianCalendar(anni, Calendar.FEBRUARY, 1);

int dayOfWeek = mycal.get(Calendar.DAY_OF_WEEK);
switch (dayOfWeek) {
    case Calendar.SUNDAY:
        break;
    case Calendar.MONDAY:
        break;
    case Calendar.TUESDAY:
        break;
    case Calendar.WEDNESDAY:
        break;
    case Calendar.THURSDAY:
        break;
    case Calendar.FRIDAY:
        break;
    case Calendar.SATURDAY:
        break;
}

Or you can replace each case with values between 1 (Sunday) and 7 (Saturday) since dayOfWeek is an int between 1 and 7.


UPDATE

To get the full name of the day:

String day = DateFormatSymbols.getInstance().getWeekdays()[dayOfWeek];
Community
  • 1
  • 1
letiagoalves
  • 11,224
  • 4
  • 40
  • 66