我想计算一年中特定周数的星期一。我就是这样做的:
final GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
calendar.clear();
calendar.set(Calendar.YEAR, 2012); // set to 2012
calendar.set(Calendar.WEEK_OF_YEAR, 20); // set to week number 20
calendar.setTimeZone(TimeZone.getTimeZone("Europe/Berlin")); // set time zone
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yy"); // german format
System.out.println(sdf.format(calendar.getTime())); // return date
这必须返回 2012 年 5 月 14 日(德语格式为 14.05.12),但它返回 2012 年 5 月 16 日,但这是错误的。
因此,对于 2012 年,其 +2,2011 年是正确的,而 2010 年是 -1。
为什么 GregorianCalendar 计算错误的日期?
在此先感谢并从德国打招呼。