我需要实时倒计时。例如,我将日期设置为(2020年2月28日),并将在(2020年2月29日)完成。在这两个日期之间,我将设置产品数量。它会不断减少。所以我希望产品数量为零我正在寻找解决方案,但找不到。
我需要帮助。谢谢问候。
这是我的js代码,
today = new Date();
BigDay = new Date("February "+day+",2020");
msPerDay = 24 * 60 * 60 * 1000;
timeLeft = (BigDay.getTime() - today.getTime());
e_daysLeft = timeLeft / msPerDay;
daysLeft = Math.floor(e_daysLeft);
e_hrsLeft = e_daysLeft*24;
hrsLeft = Math.floor(e_hrsLeft);
minsLeft = Math.floor((e_hrsLeft - hrsLeft)*60);
var productCount = 400;
document.write("<p>There are only<b> " + daysLeft + " days " + hrsLeft +" hours and " + minsLeft + " minutes left </b> Until December 25th 2025</p>");
这是一个小片段。
var productCount = 400;
function countdown(){
day = 28;
today = new Date();
BigDay = new Date("February "+day+",2020");
msPerDay = 24 * 60 * 60 * 1000;
timeLeft = (BigDay.getTime() - today.getTime());
e_daysLeft = timeLeft / msPerDay;
daysLeft = Math.floor(e_daysLeft);
e_hrsLeft = e_daysLeft*24;
hrsLeft = Math.floor(e_hrsLeft);
minsLeft = Math.floor((e_hrsLeft - hrsLeft)*60);
document.getElementById('output').innerHTML = "<p>There are only<b> " + daysLeft + " days " + hrsLeft +" hours and " + minsLeft + " minutes left </b> Until December 25th 2025</p>";
}
//Call on intial point
countdown()
window.setInterval(function(){ countdown(); productCount -=1; },60000) //Auto time after every 1 minute
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="output"></div>
希望这对您有帮助
实际上您的问题不清楚。如果您想倒数,可以按照link
时间和产品减少之间有任何关系