我正在尝试使用循环内的时刻来确定两个日期之间有多少个 60 分钟的时间段,但我得到了奇怪的结果。
const timeSlots: Moment[] = [];
let startDate = moment('2020-03-09 11:00');
let endDate = moment('2020-03-09 12:30');
while (endDate.diff(startDate, 'minutes') >= 60) {
timeSlots.push(startDate.clone());
startDate.add(30, 'minutes');
}
console.log(timeSlots);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
结果 :
2020-03-09 11:00
2020-03-09 11:00
预期的 :
2020-03-09 11:00
2020-03-09 11:30
奇怪的代码片段有效,但在我的电脑或 https://playcode.io/上却没有
一只斗牛犬
相关分类