【问题标题】:js add 7 minutes until 10 hours (00:07, 00: 14, 00:21...) [closed]js 添加 7 分钟直到 10 小时(00:07、00:14、00:21...)[关闭]
【发布时间】:2013-08-06 09:06:04
【问题描述】:

在 youtube 中,您可以每 7 分钟将广告添加到您的视频中。我想加 7 分钟 142 次。并将其打印在

console.log();

【问题讨论】:

    标签: javascript youtube


    【解决方案1】:
    // New date object, initialized to "zero"
    var d = new Date(0, 0, 0, 0, 0, 0);
    
    // While the hours property of the Date object is less than 10
    while (d.getHours() < 10) {
        // Get hours part and pad with a 0 if necessary
        var hoursString = d.getHours().toString();
        if (hoursString.length == 1) {
            hoursString = "0" + hoursString;
        }
    
        // Get minutes part and pad with a 0 if necessary
        var minutesString = d.getMinutes().toString();
        if (minutesString.length == 1) {
            minutesString = "0" + minutesString;
        }
    
        // Log the time
        console.log(hoursString + ':' + minutesString);
    
        // Add 7 minutes and let the Date object handle overflow to hours internally
        d.setMinutes(d.getMinutes() + 7);
    }
    

    您可以找到有关日期对象here 的更多信息。

    【讨论】:

    • 页面显示“1899 年 12 月 31 日星期日 10:02:00 GMT+”
    • 我需要查看每一步并得到“00:07, 00:14, 00:21, 00:28 ... 09:55)
    猜你喜欢
    • 1970-01-01
    • 2014-04-10
    • 1970-01-01
    • 2012-07-08
    • 2017-01-27
    • 2019-09-27
    • 1970-01-01
    • 2022-07-28
    • 2011-06-27
    相关资源
    最近更新 更多