使用这段代码,我得到了构成给定月份的日子,但是如果我想在星期一或星期二开始这个月,那么就像我一样?
Calendar mycal = new GregorianCalendar(anni, Calendar.FEBRUARY, 1);
int giorni = mycal.getActualMaximum(Calendar.DAY_OF_MONTH); // 28
答案 0 :(得分:0)
尝试:
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;
}
或者您可以使用介于1(星期日)和7(星期六)之间的值替换每个案例,因为dayOfWeek
是1到7之间的int
。
获取当天的全名:
String day = DateFormatSymbols.getInstance().getWeekdays()[dayOfWeek];