java根据年和周获取当前的日期时间段_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > java根据年和周获取当前的日期时间段

java根据年和周获取当前的日期时间段

 2013/9/16 12:46:29  xiyuliuguang  程序员俱乐部  我要评论(0)
  • 摘要:String[]dates=newString[7];Calendarcal=Calendar.getInstance();cal.set(Calendar.YEAR,Integer.parseInt(workhoursImsVO.getFYear()));cal.set(Calendar.WEEK_OF_YEAR,Integer.parseInt(workhoursImsVO.getFWeeks()));Calendarcal1=(Calendar)cal.clone()
  • 标签:Java
String[] dates = new String[7];
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, Integer.parseInt(workhoursImsVO.getFYear()));
cal.set(Calendar.WEEK_OF_YEAR, Integer.parseInt(workhoursImsVO.getFWeeks()));
Calendar cal1 = (Calendar)cal.clone();
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
cal.add(Calendar.DATE,cal.getActualMinimum(Calendar.DAY_OF_WEEK)-dayOfWeek);
cal.add(Calendar.DATE, 1);
Date d = cal.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
dates[0] = sdf.format(d).trim();
String temp = sdf.format(d).trim();
Calendar tempcal = Calendar.getInstance();
for(int i = 1; i < 6; i ++){
    try {
      tempcal.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(temp));
    } catch (ParseException e) {
    e.printStackTrace();
    }
    tempcal.set(cal.get(Calendar.YEAR),tempcal.get(Calendar.MONTH),   tempcal.get(Calendar.DATE) + i);
    dates[i] = sdf.format(tempcal.getTime()).trim();
        }
        cal1.add(Calendar.DATE,cal1.getActualMaximum(Calendar.DAY_OF_WEEK)-dayOfWeek);
        cal1.add(Calendar.DATE, 1);
        dates[6] = sdf.format(cal1.getTime()).trim();
发表评论
用户名: 匿名