獲取指定時間段中時間間隔源代碼--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(); 

更改返回時間格式

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

歡迎改進

不留言

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