统计页面使用的时间的数据对比
function GetDateStr(days) {
var dd = new Date();
dd.setDate(dd.getDate() - days + 1);
var ret = [];
if(days==1){
ret.push(dd.Format('WW, MM.dd'));
dd.setDate(dd.getDate() - days);
ret.push(dd.Format('WW, MM.dd'));
}else {
ret.push('{0}-{1}'.Format(dd.Format('MM.dd'), new Date().Format('MM.dd')));
dd.setDate(dd.getDate() - 1);
var _ds = dd.Format('MM.dd');
dd.setDate(dd.getDate() - days + 1);
ret.push('{0}-{1}'.Format(dd.Format('MM.dd'), _ds));
}
return ret;
}
GetDateStr(1)//前一天数据对比
GetDateStr(7)//前七天数据对比
GetDateStr(30)//前一个月天数据对比
获取想要的日期格式
Date.prototype.Format = function(fmt) { //author: meizz
var d={0:'Sunday',1:'Monday',2:'Tuesday',3:'Wednesday',4:'Thursday',5:'Friday',6:'Saturday'};
var o = {
"M+": this.getMonth() + 1, //month
"d+": this.getDate(), //day
"h+": this.getHours(), //hours
"m+": this.getMinutes(), //minutes
"s+": this.getSeconds(), //seconds
"S": this.getMilliseconds(), //Milliseconds
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
if(/(W+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? ((d[this.getDay()]).substr(0,3)) : (d[this.getDay()]));
return fmt;
};