求算法。我已经有一种方法,但是貌似不对 java,算法 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 兄弟,吧你的代码弄了一下,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:201405the week:201406the week:201407。。the week:201446the week:201447the week:201448 用java+access编写 在线题库系统?我是新手,老师的作业,想问一下大概思路? 我是菜鸟…大虾们进来看看吧… hibernate 中的问题 调用javabean出乎意外 挑战csdn高手 请问用SmartUpload上传 ECLIPSE web项目不能debug 一个很郁闷的问题,帮我看看好吗 如何屏蔽某个字符 可以把JSP页面里的表格的每个列名传递到后台吗 java日期格式转换问题 关于电影院的统计问题
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