Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
315 views
in Technique[技术] by (71.8m points)

怎么通过一个日期算出这一天所有的时间间隔?

例如给出时间 2020-09-23;
算出每隔一分钟的时间如下:

[
    '2020-09-23 00:00',
    '2020-09-23 00:01',
    '2020-09-23 00:02',
    '2020-09-23 00:03',
        ...
    '2020-09-23 23:58',
    '2020-09-23 23:59',
]

谢谢


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
function output(dateStr) {
    let arr = [];
    for (let i = 0; i <= 23; i++) {
        const h = i < 10 ? `0${i}`: `${i}`;
        for (let j = 0; j <= 59; j++) {
            const m = j < 10 ? `0${j}`: `${j}`;
            arr.push(`${dateStr} ${h}:${m}`);

        }
    }
    return arr;
}

output('2020-09-24'); // [ "2020-09-24 00:00", "2020-09-24 00:01", "2020-09-24 00:02", ...]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...