0

大家好,我正在使用 jquery 倒计时,我想将其设置为 16 小时,但我一生都无法弄清楚回调中的日期格式设置;谁能帮忙?

$(function () {
   var austDay = new Date();
   austDay = new Date(austDay.getFullYear() + 1, 0 - 1, 15);
   $('.time').countdown({until: austDay, 
   layout: '{dn} {dl}, {hn} {hl}, {mn} {ml}, and {sn} {sl}'});
   $('#year').text(austDay.getFullYear());  
});

它在上面代码的第 3 行中配置,这里是插件网站的链接。

提前致谢

4

2 回答 2

3

您可以使用以下代码将其设置为从现在起 16 小时

$(function () {
   var austDay = new Date();
   austDay.setHours(austDay.getHours() + 16);
   $('.time').countdown({until: austDay,                          
   layout: '{hn} {hl}, {mn} {ml}, and {sn} {sl}'});
   $('#year').text(austDay.getFullYear());  
});​

或者更好的是,您可以使用until如下选项

 $('.time').countdown({
     until: "16 hours",
     layout: '{hn} {hl}, {mn} {ml}, and {sn}    {sl}'
   });

但正如您所见,它为当前日期对象增加了 16 个小时,每次重新加载页面时都会重置它。如果您希望它持续存在,则必须使用日期字符串手动构建对象。

这是一个工作小提琴http://jsfiddle.net/joycse06/SDFLn/

于 2012-05-17T14:04:24.773 回答
2

如果您只是想要一个 16 小时的倒数计时器,请使用 build0in 功能

$('.time').countdown({until: +57600, layout: '{dn} {dl}, {hn} {hl}, {mn} {ml}, and {sn} {sl}'});

其中 57600 秒 = 16 小时

于 2012-05-17T14:04:23.770 回答