【问题:】时间格式yyyymm,(mm为周一年有52周,01,01.。。。)求201401 201412之间的周数
========================我的算法
如果换成201402 201412就很正常。
不知道为什么?
joda time jar这个jar谁用过,这个jar能解决上面的问题不?求解
========================我的算法
package com.test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class TestTime {
public static void main(String[] args) {
getWeek("201401","201412");
}
public static String getWeek(String startDate,String endDate)
{
String[] weeks = null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyyww");
try {
Date start = sdf.parse(startDate);
Date end = sdf.parse(endDate);
Long l = end.getTime() - start.getTime();
Long l2= l/(1000*3600*24*7);
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);
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:201301
the week:201402
the week:201403
the week:201404
the week:201405
the week:201406
the week:201407
the week:201408
the week:201409
the week:201410
the week:201411
the week:201412
如果换成201402 201412就很正常。
不知道为什么?
joda time jar这个jar谁用过,这个jar能解决上面的问题不?求解