/ 中存储网

oracle查看当前日期是第几个星期的方法

2014-06-07 07:24:28 来源:中存储网
系统当前时间是多少周,就是是今年的第几个星期
 相关操作代码如下:

 int year=2011;
        int week=1;
        Calendar calFirstDayOfTheYear = new GregorianCalendar(year,
                Calendar.JANUARY, 1);
            calFirstDayOfTheYear.add(Calendar.DATE, 7 * (week-1));
 
            int dayOfWeek = calFirstDayOfTheYear.get(Calendar.DAY_OF_WEEK);
 
            Calendar calFirstDayInWeek = (Calendar)calFirstDayOfTheYear.clone();
            calFirstDayInWeek.add(Calendar.DATE,
                calFirstDayOfTheYear.getActualMinimum(Calendar.DAY_OF_WEEK) - dayOfWeek);
            Date firstDayInWeek = calFirstDayInWeek.getTime();
            System.out.println(year + "年第" + week + "个礼拜的第一天是" + ReportDateUtil.getFromatDay().format(firstDayInWeek));
 
            Calendar calLastDayInWeek = (Calendar)calFirstDayOfTheYear.clone();
            calLastDayInWeek.add(Calendar.DATE,
                calFirstDayOfTheYear.getActualMaximum(Calendar.DAY_OF_WEEK) - dayOfWeek);
            Date lastDayInWeek = calLastDayInWeek.getTime();
            System.out.println(year + "年第" + week + "个礼拜的最后一天是" + ReportDateUtil.getFromatDay().format(lastDayInWeek));