更改jQuery倒计时的格式?

更改jQuery倒计时的格式?,jquery,jquery-countdown,Jquery,Jquery Countdown,我试图让我的倒计时计时器显示0年,0个月,7天0分钟等,但无论我尝试输入什么数字,只要我努力计算,我都会得到7349天等答案。下面是代码: // jQuery Countdown styles 1.6.1. - plugin by Keith Wood function counter_start() { var austDay = new Date(); austDay = new Date(austDay.getFullYear() - 2016, 0 - 7, 0); //

我试图让我的倒计时计时器显示
0年,0个月,7天0分钟
等,但无论我尝试输入什么数字,只要我努力计算,我都会得到7349天等答案。下面是代码:

// jQuery Countdown styles 1.6.1. - plugin by Keith Wood
function counter_start() {
    var austDay = new Date();
    austDay = new Date(austDay.getFullYear() - 2016, 0 - 7, 0); // Examples: (austDay.getFullYear() + 1, 3 - 1, 6) or (2013, 3 - 1, 6)
    $("#defaultCountdown").countdown({
        until: austDay, 
        format: 'DHMS'
    });
}

我查过,读过,问过其他人,但这不是我的领域,我就是不明白。有人给我提个醒吗?非常感谢你的阅读。杰米。

你的格式不准确。请尝试:

$('#defaultCountdown').countdown({
    until: austDay, 
    format: 'YODM'
});
Y=年

O=月

D=天

M=分钟


在您的案例中,此选项很容易使用。 在var target_date中指定要倒计时的日期。 您可以在countdown.innerhtml的脚本末尾更改输出格式。(已经是Y:M:D:S格式)

并将html放入正文中:

<span id="countdown"></span> 

试试这个倒计时插件

通过自定义custom.js来尝试这一点

 $('#clock').countdown('2016/10/31').on('update.countdown',   
     function(event) {
   var $this = $(this).html(event.strftime(''

     + '<div><span>%-d</span>day%!d</div>'
     + '<div><span>%H</span>hr</div>'
     + '<div><span>%M</span>min</div>'
     + '<div><span>%S</span>sec</div>'));
 });
$(“#时钟”)。倒计时('2016/10/31')。在('update.countdown')上,
功能(事件){
var$this=$(this.html)(event.strftime(“”)
+“%-dday%!d”
+“%Hhr”
+“%Mmin”
+“%Ssec”);
});

我喜欢官方文档中的这种方法,可以应用您想要的任何格式,由您自己定制:

$(selector).countdown({ 
    until: liftoffTime, onTick: watchCountdown}); 

function watchCountdown(periods) { 
    $('#monitor').text('Just ' + periods[5] + 
        ' minutes and ' + periods[6] + ' seconds to go'); 
}
在官方文档中,他们准确地解释了
onTick
的功能以及您可以如何使用它:

每次倒计时更新时调用的回调函数 它本身在函数中,这是指保存 小装置。当前倒计时周期的数组(int[7]——基于 格式设置)作为参数传递:[0]是年,是月, [2] 是星期,[3]是天,[4]是小时,[5]是分钟,[6]是 秒


我的awnser怎么了?我以为我的awnser能帮上忙?
$(selector).countdown({ 
    until: liftoffTime, onTick: watchCountdown}); 

function watchCountdown(periods) { 
    $('#monitor').text('Just ' + periods[5] + 
        ' minutes and ' + periods[6] + ' seconds to go'); 
}