我有這個簡單的倒計時:function offer_countdown_timer(countdown_start, countdown_time, update, complete) { var start = new Date(countdown_start).getTime(); var interval = setInterval(function() { var now = countdown_time-(new Date().getTime()-start); if( now <= 0) { clearInterval(interval); complete(); } else { update(Math.floor(now/1000)); } },100); // the smaller this number, the more accurate the timer will be}在這里我稱之為:<script> offer_countdown_timer( '<%= s.created_at%>', 3600000, // 1 hour in milliseconds function(timeleft) { // called every step to update the visible countdown var txt = timeleft+' seconds'; $('#tender_countdown_<%= s.id %>').html(txt); //$('#tender_countdown_<%= s.id %>').html(moment(txt).format('HH:mm:ss')); }, function() { $('#product_<%= s.id %>').html('Offer has expired!'); } );</script>這個的輸出是:773 seconds(它正在倒計時)我想看到這樣的東西(HH:ss:mm):00:12:53(并倒數)。我嘗試使用它(使用 Moment.js lib - https://momentjs.com/docs/):$('#tender_countdown_<%= s.id %>').html(moment(txt).format('HH:mm:ss')); 但在這種情況下,輸出是這樣的:01:00:00時間信息有誤,不倒計時。這是為什么?如何正確格式化倒計時時間?
在倒計時中將時間從秒格式化為 HH:MM:SS
Helenr
2022-06-05 16:41:07