js根据指定日期获取周一到周日的所有日期

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var d = '2015-01-28';
var weekRange = [];
for (var i=0;i<7;i++)
{
var d1 = Date.parse(d.replace(/-/g, "/"));
var date = new Date(d1);
date = date.valueOf(),
date = date + i * 24 * 60 * 60 * 1000
date = new Date(date),
mymonth = date.getMonth()+1,
myday = date.getDate(),
myyear= date.getFullYear();
year=(myyear > 200) ? myyear : 1900 + myyear;
if(mymonth >= 10){mymonth=mymonth;}else{mymonth="0" + mymonth;}
if(myday >= 10){myday=myday;}else{myday="0" + myday;}
var outputdate = year + "-" + mymonth + "-" + myday;
weekRange.push(outputdate);
}

 

坚持原创技术分享,您的支持将鼓励我继续创作!