翻转计数器特定开始日期

时间:2014-08-23 17:18:19

标签: javascript html date counter increment

我正试图让一个柜台从9月1日到12月13日从5,000,000,000开始倒计时。

我能够使计数器增加(-1)并且我能够将数字改为50亿。但是,我无法设置该功能启动的具体时间。我想倒计时从9月1日下午5点开始。

点击here获取代码。 (我在我的版本中修改了index.html,它没有太大的不同,所以我给的是原始链接)

1 个答案:

答案 0 :(得分:0)

您无需将时间“重置”到9月1日。

只需获取12月13日的时间戳(1418428800 2014-12-13 at 00:00:00 UTC,如果您需要不同的时间或时区,请使用http://www.epochconverter.com进行计算)页面以秒计算差异并从那一刻开始计数器。

示例:

var endTime = 1418428800 // 2014-12-13 00:00:00 UTC

// The function that is run every second to update the displayed counter
function updateCounter() {
    var now = parseInt(Date.now() / 1000)
    var countdown = endTime - now
    // Display the value of countdown somewhere in the page
}
setInterval(updateCounter, 1000)