返回指定时间段相同间隔数组
16lz
2021-01-22
返回指定时间段相同间隔数组
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)
样式
thenDate = thenDate.getFullYear() + "-" + (thenDate.getMonth() + 1) + "-" + thenDate.getDate();
欢迎改进
by h.k
更多相关文章
- JavaScript数组中的唯一计数,按计数排序
- Javascript sort()不适用于Chrome中超过10个对象的数组
- 获取JavaScript数组元素的最大长度
- 对多维数组中的列进行排序
- 获取拆分字符串数组的最后一个元素
- JS将字符串转换为数组
- 将textarea值附加到现有数组javascript
- ECMAScript6(6):数组的扩展
- 希望日期开始结束在一个数组中的while循环中为一个房间ID