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