我有一個程序,它在很大程度上依賴於確定該年度的週數。我已經完成了腿部工作,並找出了所有會導致這種方法並解決的問題。我的作品完美多年,有53周等。我唯一的問題是,當我在2.2版本的仿真器上運行它時,它是完美的,就像這是第19周,它是正確的。當我在G1手機上運行它時,本週顯示爲20.我該如何解決這個問題?Android的週數錯了電話,但沒有模擬器
這裏是我的星期代碼:(我要離開這一個評論,但我的賬號還沒有評論權限)
/**
* Format the date into a number that is the year*100 plus the week i.e. 2008 and its week 11
* would show as 811
* @param - String of a date to create a week id, must be in format of 2011-01-31 (YYYY-MM-DD)
* @return returns next weeks id
*/
public static int getWeekId(String date){
// Set the first day of week to Monday and set the starting new year weeks
// as a full first week in the new year.
Calendar c = Calendar.getInstance();
c.setFirstDayOfWeek(Calendar.MONDAY);
c.setMinimalDaysInFirstWeek(7);
if (!date.equalsIgnoreCase("")) {
String[] token = date.split("-", 3);
int year = Integer.parseInt(token[0]);
int month = Integer.parseInt(token[1])-1; // months are 0-11 stupid..
int day = Integer.parseInt(token[2]);
c.set(year, month, day);
}
int yearWeek = ((c.get(Calendar.YEAR) - 2000)*100 + (c.get(Calendar.WEEK_OF_YEAR)));
Log.d("getWeekId()"," WEEK_OF_YEAR: " + c.get(Calendar.WEEK_OF_YEAR));
return yearWeek;
}
我做一些後期處理正確弄清楚年,年周實際上是1052第一週今年開始時間Jan 03和1月1日和2日是在2010年用了52周說,主問題是在2.2屬下19個星期的今天和我的G1(1.6),其20這是怎麼回事,以及如何解決星期? – JPM 2011-05-13 05:16:01