1 var SetSearchDate = function (sign, sid, eid) {//sign 标识符区分本周本月本年,sid开始时间id,eid结束时间id 2 var now = new Date(); 3 var nowDayOfWeek = now.getDay(); //今天本周的第几天 4 var nowMonth = now.getMonth() + 1; //当前月 5 var nowYear = now.getFullYear(); //当前年 6 7 if (sign == 1)//本周 8 { 9 var first_milliseconds = new Date().getTime() - 1000 * 60 * 60 * 24 * (nowDayOfWeek - 1); 10 var last_milliseconds = first_milliseconds + 1000 * 60 * 60 * 24 * 6; 11 $("#" + sid).val(formatDate(new Date(first_milliseconds))); 12 $("#" + eid).val(formatDate(new Date(last_milliseconds))); 13 } else if (sign == 2)//本月 14 { 15 var firstdate = nowYear + '-' + nowMonth + '-01'; 16 var lastdate = nowYear + '-' + nowMonth + '-' + new Date(nowYear, nowMonth, 0).getDate(); 17 $("#" + sid).val(firstdate); 18 $("#" + eid).val(lastdate); 19 } else if (sign == 3)//本年 20 { 21 $("#" + sid).val(nowYear + '-01' + '-01'); 22 $("#" + eid).val(nowYear + '-12' + '-31'); 23 } 24 }