解决方案 »

  1.   

    兄弟,吧你的代码弄了一下,
    1  SimpleDateFormat sdf = new SimpleDateFormat("yyyyww"); 这里你开始是要取1月和12月的时间,而不是1周和12周的时间,所以要改成 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM"); 
       在week数组赋值前增加这样一句,换成取得周的: sdf = new SimpleDateFormat("yyyyww");
                    weeks[i] = sdf.format(cal.getTime()); public static String getWeek(String startDate,String endDate)
        {
            String[] weeks = null;
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
            try {
                Date start = sdf.parse(startDate);
                Date end = sdf.parse(endDate);            Long l = end.getTime() - start.getTime();
                Long l2= l/(1000*3600*24*7);
                System.out.println(l2);
                int length = l2.intValue()+1;
                Calendar cal = Calendar.getInstance();
                cal.setTime(start);
                weeks = new String[length];
                for(int i = 0;i<length;i++)
                {
                    cal.add(Calendar.WEEK_OF_YEAR, i);
                    sdf = new SimpleDateFormat("yyyyww");
                    weeks[i] = sdf.format(cal.getTime());
                    System.out.println("the week:"+weeks[i]);
                    if(i!=0)
                    {
                        cal.add(Calendar.WEEK_OF_YEAR, -i);
                    }
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
            return null;
        }=============================运行结果
    the week:201405
    the week:201406
    the week:201407
    。。
    the week:201446
    the week:201447
    the week:201448