js加7分钟直到10小时(00:07,00:14,00:21 ......)

时间:2013-08-06 09:06:05

标签: javascript youtube

在youtube中,您可以每7分钟为视频添加一次广告。我想要加7分钟142次。并在

中打印
console.log();

1 个答案:

答案 0 :(得分:0)

// 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的更多信息。