代码是:
Calendar c = Calendar.getInstance();
c.set(mYear, mMonth, mDay);
int week = c.get(Calendar.WEEK_OF_YEAR);
日历设置为 2012/11(NOV)/06
在 Android 4.0 上,周数为 45,而在 Android 4.1 上,周数为 46
谁能解释一下,或者告诉我正确的使用方法。提前致谢。
您的 mYear、mMonth、mDay 是否指向 currentDate ?如果是这样,您可以这样做:
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
int week = calendar.get(Calendar.WEEK_OF_YEAR);
如果没有,则明确设置它们:
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, mYear);
calendar.set(Calendar.MONTH, mMonth);
calendar.set(Calendar.DAY_OF_YEAR, mDay);
int week = calendar.get(Calendar.WEEK_OF_YEAR);