日期:2014-05-16  浏览次数:20350 次

高分求教 js 如何取两段日期之间的所有天的日期值
例如 startday=2009-12-1 ,endday=2010-3-31,
我要的days=“2009-12-1,2009-12-2,2009-12-3.......2010-3-30,2010-3-31” ,
请大家帮忙,在线等,
要求用js实现

------解决方案--------------------
JScript code
<script>
d1 = new Date(2009,11,1)
d2 = new Date(2010,2,31)
s = []
days = (Date.parse(d2)-Date.parse(d1))/1000/60/60/24
for(i = 0;i<=days;i++)
{
d =  new Date(2009,11,1+i)
d = d.getFullYear() + "-" + (d.getMonth()+1) + "-" + d.getDate()
s.push(d)
}
document.write(s.join("<br/>"))
</script>

------解决方案--------------------
JScript code


//YYYY-MM-DD格式输入
function Todo(begin, end)
{
    var ab = begin.split("-");
    var ae = end.split("-");
    var db = new Date();
    db.setFullYear(ab[0], ab[1]-1, ab[2]);
    var de = new Date();
    de.setFullYear(ae[0], ae[1]-1, ae[2]);

    var a = [];
    for (var i=0,temp=db;temp < de;i++)
    {
        a[i] = GetDate(temp);
        temp.setTime(temp.getTime() + 24*60*60*1000);
    }
    a[i] = GetDate(de);

    return a.join();

}

//返回1900-01-01格式的字符串
function GetDate(d)
{
    return d.getFullYear() + "-" + (d.getMonth()+1) + "-" +  d.getDate();
}


document.write(Todo("2009-12-31", "2010-03-31"));

------解决方案--------------------
探讨
JScript code
<script>
d1 = new Date(2009,11,1)
d2 = new Date(2010,2,31)
s = []
days = (Date.parse(d2)-Date.parse(d1))/1000/60/60/24
for(i = 0;i<=days;i++)
{
d = new Date(2009,11,1+i)
d = d.g……

------解决方案--------------------
孟子真厉害,顶起