获取指定时间段中时间间隔源代码--h.k

var aaa = function IntervalDate_Arr(startStr, endStr, interval) {
    popArr = [];
    var now = new Date(startStr);
    var secondInt = (new Date(endStr) - now);
    var days = Math.abs(secondInt / 86400000);
    var freq = Math.ceil(days / interval);
    var i = 0;
    var thenDate = 0;
    while (i <= freq) {
        thenDate = new Date(now - 0 + i * interval * 86400000);
        thenDate = thenDate.getFullYear() + "-" + (thenDate.getMonth() + 1) + "-" + thenDate.getDate(); 
        popArr.push(thenDate);
        i++;
    }
    return popArr;
}


aaa('2016-11-07', '2017-11-7', 7)


语言:js

作用:输入开始时间、结束时间、间隔时间 返回 指定的间隔日期数组

通过更改

thenDate = thenDate.getFullYear() + "-" + (thenDate.getMonth() + 1) + "-" + thenDate.getDate(); 

更改返回时间格式

=========================分隔符=========================

欢迎改进

不留言

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章