系統目前時間是多少周,就是是今年的第幾個星期
複製代碼 代碼如下:select to_char(sysdate,'ww') ,to_char(sysdate,'iw') from dual;
select to_char(sysdate,'ddd') from dual;
select TRUNC(SYSDATE,'MM') from dual;1)
ww的演算法為每年1月1日為第一周開始,date+6為每一周結尾
例如:20050101為第一周的第一天,而第一周的最後一天為20050101+6=20050107
公式: 每周第一天 :date + 周 * 7 - 7 每周最後一天:date + 周 * 7 - 12)
iw的演算法為星期一至星期日算一周,且每年的第一個星期一為第一周,
例如:20050101為星期六,所以用iw的演算法是前年的53周,而20050103之後才是第一周的開始。
公式: 每周第一天 :next_day(date) + 周 * 7 - 7每周最後一天:next_day(date) + 周 * 7 - 13)
其它:
A、查今天是 "本月" 的第幾周 SELECT TO_CHAR(SYSDATE,'WW') - TO_CHAR(TRUNC(SYSDATE,'MM'),'WW') + 1 AS "weekOfMon" from dual; 或 SELECT TO_CHAR(SYSDATE,'W') AS "weekOfMon" from dual;
B、查今天是 "今年" 的第幾周 select to_char(sysdate,'ww') from dual; 或 select to_char(sysdate,'iw') from dual;
統計哪年哪個星期的哪一天:複製代碼 代碼如下: 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));