How do I set a specific GMT end time for the classyCountdown.js plugin?

耗尽温柔 提交于 2019-12-10 09:38:26

问题


RE: http://www.class.pm/files/jquery/classycountdown/

This simple jquery countdown plugin presents exactly how I want it to, but the trigger code at the moment only sets a target end time relative to the page load.

$('.countdown').ClassyCountdown({
    theme: "flat-colors",
    end: $.now() + 10000
});

What I want to ultimately do is set the end time relative to a specific GMT/UTC date and time.

Is this possible, and how is it done/coded?


回答1:


You need to dig a little into Unix/Epoch time.

Both now and end parameters are used to specify the start and end times respectively in Epoch time. The jQuery function $.now() returns the the present time in milliseconds. Divide the returned value by 1000 and the rest is really simple.

Say you want to count down to 9:00 AM , 25th December, 2015. You need to calculate the Epoch time to the date first. The Epoch timestamp for this example is 1451034000. This is in seconds, not milliseconds. So the concerned part of your code should look like this:

$('#countdown').ClassyCountdown({
                                   now:  $.now()/1000 ,
                                   end:  '1451034000' ,
                                   ...
                                   ...
                                 });



回答2:


Say you want to count down to 9:00 AM , 25th December, 2015:

$('.countdown').ClassyCountdown({
    theme: "flat-colors",
    now: $.now() / 1000,
    end: Date.UTC(2015, 11, 25, 9, 0, 0) / 1000
});

Be aware, that month count starts with 0.



来源:https://stackoverflow.com/questions/27984489/how-do-i-set-a-specific-gmt-end-time-for-the-classycountdown-js-plugin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!