欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java根据年和周获取当前的日期时间段 博客分类: 开发实例 java日期

程序员文章站 2024-03-16 19:15:52
...
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();
相关标签: java 日期