js获取当前日期:
var d = new Date();var str = d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();alert(str); //当前日期
js获取前n天的日期:
function getBeforeDate(n){ var n = n; var d = new Date(); var year = d.getFullYear(); var mon=d.getMonth()+1; var day=d.getDate(); if(day <= n){ if(mon>1) { mon=mon-1; } else { year = year-1; mon = 12; } } d.setDate(d.getDate()-n); year = d.getFullYear(); mon=d.getMonth()+1; day=d.getDate(); s = year+"-"+(mon<10?('0'+mon):mon)+"-"+(day<10?('0'+day):day); return s; }
新闻热点
疑难解答