[javascript]代码库
function getPreviousWeek(year,month,day) {
var today = new Date(year,month - 1 ,day);
var week = today.getDay();
if (week == 0 ) {
week = 7 ;
}
var monday = new Date(today.valueOf() - (week + 6 ) * 24 * 60 * 60 * 1000 );
var sunday = new Date(monday.valueOf() + 6 * 24 * 60 * 60 * 1000 );
var prevWeek = new Object();
prevWeek['monday'] = monday.getFullYear() + "-" + ((monday.getMonth() + 1 ).toString().length == 1 ? ( "0" + (monday.getMonth() + 1 )):(monday.getMonth() + 1 )) + "-" + (monday.getDate().toString().length == 1 ? "0" + monday.getDate():monday.getDate());
prevWeek['sunday'] = sunday.getFullYear() + "-" + ((sunday.getMonth() + 1 ).toString().length == 1 ? ( "0" + (sunday.getMonth() + 1 )):(sunday.getMonth() + 1 )) + "-" + (sunday.getDate().toString().length == 1 ? "0" + sunday.getDate():sunday.getDate());
return prevWeek;
}