guys,i am confused by invoking the following method:Calendar.getInstance().get(Calendar.WEEK_OF_YEAR)
,the result got from that method is not right.Here is my Code:
Locale.setDefault(Locale.CHINA);
Calendar calendar = Calendar.getInstance();
//we think Monday is the first day of a week in China,but not Sunday.
calendar.setFirstDayOfWeek(Calendar.MONDAY);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String dateString = "2010-01-01";
calendar.setTime(sdf.parse(dateString));
System.out.println("DateString: " + dateString + ", week: " + calendar.get(Calendar.WEEK_OF_YEAR));
dateString = "2010-12-27";
calendar.setTime(sdf.parse(dateString));
System.out.println("DateString: " + dateString + ", week: " + calendar.get(Calendar.WEEK_OF_YEAR));
The result is
DateString: 2010-01-01, week: 1//This may be wrong?
DateString: 2010-12-27, week: 1//This result is definitely wrong.
So here is the question, how to get the right week of year number using Calendar instance?