我有一个格里高利日期,我希望在一周中得到它。我试过这个,但得错了答案:
Calendar calendar = new GregorianCalendar();
calendar.set(myYear, myMonth, myDay);
int result = calendar.get(Calendar.DAY_OF_WEEK);
switch (result) {
case Calendar.SUNDAY:
Log.i("DayOfWeek", "SUN");
break;
.
.
.
default:
startDay = 0;
break;
}
什么是问题?
答案 0 :(得分:1)
最后我发现了问题!上面的代码是正确的,但您应该传递标准月份值(0 ... 11)而不是(1 ... 12):
Calendar calendar = new GregorianCalendar();
calendar.set(myYear, myMonth-1, myDay);
int result = calendar.get(Calendar.DAY_OF_WEEK);
switch (result) {
case Calendar.SUNDAY:
Log.i("DayOfWeek", "SUN");
break;
.
.
.
default:
startDay = 0;
break;
}