gpt4 book ai didi

javascript - 获取间隔

转载 作者:行者123 更新时间:2023-12-02 15:15:39 25 4
gpt4 key购买 nike

一切都按预期进行,但我试图按开始和结束将这些间隔放入对象中,目前它返回一个带有时间的数组:7:00 - 7:15,我想要开始:7:00,结束:7:15。这是我当前的代码。

  var setIntervals = function (oc, start, end, inc) {
start = start.toString().split(':');
end = end.toString().split(':');
inc = parseInt(inc, 10);

var pad = function (n) { return (n < 10) ? '0' + n.toString() : n; },
startHr = parseInt(start[0], 10),
startMin = parseInt(start[1], 10),
endHr = parseInt(end[0], 10),
endMin = parseInt(end[1], 10),
currentHr = startHr,
currentMin = startMin,
previous = currentHr + ':' + pad(currentMin),
current = '',
r = [];

do {
currentMin += inc;
if ((currentMin % 60) === 0 || currentMin > 60) {
currentMin = (currentMin === 60) ? 0 : currentMin - 60;
currentHr += 1;
}
current = currentHr + ':' + pad(currentMin);
r.push(previous + ' - ' + current);
previous = current;
} while (currentHr !== endHr);

return r;
};
var timeInterVals=setIntervals("","<?php echo $closed_now ?>","<?php echo $closed_end ?>","15");

此代码由 JavaScript Setting Time Difference through Loop In Array 提供

我知道我需要将开始和结束返回到我的 setIntervals 中,但我不断遇到语法问题。

这是我当前放入数组的方式。

for (var i in timeInterVals){

var timearr = timeInterVals[i];

allHours.clinic.push({
"open or closed" : "",
"time" : timearr
});
}

我的想法是我需要在 setInterval 函数中迭代到开始和结束。

谢谢,

最佳答案

而不是

r.push(previous + ' - ' + current);

做,

r.push({"start":previous, "end":current});

关于javascript - 获取间隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34499545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com