Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android手机周号错误,但不是模拟器_Android_Calendar_Numbers - Fatal编程技术网

Android手机周号错误,但不是模拟器

Android手机周号错误,但不是模拟器,android,calendar,numbers,Android,Calendar,Numbers,我有一个计划,它在很大程度上依赖于确定一年的周数。我已经做了腿部工作,并找出了所有的问题,将导致和解决这个方法。我在53周左右的时间里工作得很完美。我唯一的问题是,当我在2.2版模拟器上运行它时,它工作得非常完美,就像这是第19周,它是正确的。当我在手机上运行G1时,一周显示20次。我该如何解决这个问题 以下是我的周代码: /** * Format the date into a number that is the year*100 plus the week i.e. 2008 and i

我有一个计划,它在很大程度上依赖于确定一年的周数。我已经做了腿部工作,并找出了所有的问题,将导致和解决这个方法。我在53周左右的时间里工作得很完美。我唯一的问题是,当我在2.2版模拟器上运行它时,它工作得非常完美,就像这是第19周,它是正确的。当我在手机上运行G1时,一周显示20次。我该如何解决这个问题

以下是我的周代码:

/**
 * 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;

}
(我会将其保留在评论中,但我的帐户还没有评论权限。)


使用2011-01-01调用时,代码当前返回1152。这是你想要的吗?

不管它值多少钱,它可能比你写的更复杂。我并不是说这意味着什么,只是可能有很多有趣的奇怪的案例你没有考虑过。有一个很好的Java库,它知道很多关于时间的信息,并且可能已经编写了这些代码,请查看:

显然这是android手机中的一个bug…所以在使用android 1.6时要注意这一点。

我对此做了一些后处理,以正确计算年份,一周实际上是1052年。今年的第一周从1月3日开始,1月1日和2日是2010年的第52周。话虽如此,今天的主要议题是2.2版本的第19周和我的G1(1.6)版本的第20周。是的,我理解Java时代的复杂性,多年来一直在linux服务器上运行这个版本的Java代码。我现在把其中的一些移植到了android上,我发现在某些手机上,周数是错误的。我知道joda有些东西,但我正试图将安装包降到最低限度,不必处理第三方产品的许可问题,甚至是开源产品。看来我必须通过使用Web服务来给我周数来解决这个问题。