在两个日期之间迭代直到第一个日期在第二个日期之前



我在unix中有两个日期:

let start: number = 1632988953;
const end: number  = 1638259353;

我需要迭代这两个日期,巫婆将在每次迭代中计算新的start日期。

我有一个while结构,如下所示:

const datesArray = [];
while (start <= end) {
let newDate = dayjs.unix(start).add(5, 'day').unix();
datesArray.push(newDate);

start = newDate;
}

当我在函数中启动这个while时,它会无限迭代杀死我的浏览器,有人能告诉我这里有什么问题吗?

工作正常,执行代码片段自己看看

let start = 1632988953;
const end  = 1638259353;
let condition = true;
console.log("before : ",condition);
const datesArray = [];
while (start <= end) {
let newDate = dayjs.unix(start).add(5, 'day').unix();
datesArray.push(newDate);
start = newDate;
condition = start <= end;
}
console.log("after : ",condition);
<script src="https://unpkg.com/dayjs@1.8.21/dayjs.min.js"></script>
<script>dayjs().format()</script>

相关内容

最新更新