从现在到即将到来的一天(上午)之间的剩余分钟数,在Javascript 中获取最简洁、最高效的方法01:00是什么?然后,一旦当前时间在 之后01:00,我就开始计算与下一个时间的差异。
3 回答

杨__羊羊
TA贡献1943条经验 获得超7个赞
let now = new Date();
let next1am = new Date();
next1am.setHours(1, 0, 0, 0); // same as now, but at 01:00:00.000
if (next1am < now) next1am.setDate(next1am.getDate() + 1); // bump date if past
let millisecondDiff = next1am - now;
let minuteDiff = Math.floor(millisecondDiff / 1000 / 60);
添加回答
举报
0/150
提交
取消