系统当前时间是多少周,就是是今年的第几个星期
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));