如何将年份添加到倒计时器中

时间:2016-04-05 18:39:17

标签: javascript jquery countdown

我有这段代码,我想添加"年"它。我该怎么办?



 function updateTimer(){
   
    // Get the element to append to
    var counter = document.getElementById("Example");
    // Set the targetDate
    var targetDate = new Date("July 27, 2012 19:30:00");

    var remainingSeconds = ~ ~((targetDate - new Date()) / 1000);
    var remainingTime = {
        "days": remainingSeconds / (60 * 60 * 24),
        "hours": (remainingSeconds % (60 * 60 * 24)) / (60 * 60),
        "minutes": (remainingSeconds % (60 * 60)) / 60,
        "seconds": remainingSeconds % 60
    };

    var str = "Time left is :: ";
    for (var i in remainingTime) {
        str += ~ ~remainingTime[i] + " " + i + ", ";
    }
    // Store the result in the element
    counter.innerHTML = str.substring(0, str.length - 2);
 }

 // Update the timer every 1 second
 setInterval(updateTimer, 1000);

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<h1 id="Example"></h1>
&#13;
&#13;
&#13;

我试图自己做,但后来显示了天+年,所以例如10年会显示&#34; 10年3650天......等等#34>。

0 个答案:

没有答案
相关问题