php:
本周一 echo date(‘Y-m-d‘,(time()-((date(‘w‘)==0?7:date(‘w‘))-1)*24*3600)); //w为星期几的数字形式,这里0为周日 本周日 echo date(‘Y-m-d‘,(time()+(7-(date(‘w‘)==0?7:date(‘w‘)))*24*3600)); //同样使用w,以现在与周日相关天数算
JS:
//本周周一 function showWeekFirstDay()
{
var Nowdate=new Date();
var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()+6)*86400000);
M=Number(WeekFirstDay.getMonth())+1
return WeekFirstDay.getYear()+"-"+M+"-"+WeekFirstDay.getDate();
}
本周最后天
//本周周天
function showWeekLastDay()
{
var Nowdate=new Date();
var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()+6)*86400000);
var WeekLastDay=new Date((WeekFirstDay/1000+6*86400)*1000);
M=Number(WeekLastDay.getMonth())+1
return WeekLastDay.getYear()+"-"+M+"-"+WeekLastDay.getDate();
}