試圖找出2個日期摸出年:月:日離開
我想我靠近之間剩下的時間,但我得到了我的天,年故障的結果,我也檢查過其他解決方案,但它們是不同於我嘗試這樣做的方式......我可以根據自己的方式做我需要的嗎?
var seconds= Math.floor((timeLeft/1000)%60);
var minutes= Math.floor((timeLeft/(1000*60))%60);
var hours= Math.floor((timeLeft/(1000*60*60))%24);
var dayz= Math.floor((timeLeft/(1000*60*60*24))%31);
var years= Math.floor((timeLeft/(1000*60*60*24*31))%12);
$(document).ready(function(){
var currentDate = new Date(2017, 08, 07 , 14 , 33, 20); //set fixed dates to test with
var futureDate = new Date(2018, 08, 07 , 14 , 33, 20); //set fixed dates to test with
var countDown = setInterval(function() {
\t \t \t var currentD = new Date(2017, 08, 07 , 14 , 33, 20); //set fixed dates to test with
\t \t \t var timeLeft = new Date();
\t \t \t timeLeft = futureDate - currentD;
var seconds= Math.floor((timeLeft/1000)%60);
\t \t \t var minutes= Math.floor((timeLeft/(1000*60))%60);
\t \t \t var hours= Math.floor((timeLeft/(1000*60*60))%24);
\t \t \t var dayz= Math.floor((timeLeft/(1000*60*60*24))%31);
var years= Math.floor((timeLeft/(1000*60*60*24*31))%12);
$('#timeLeft').text(years + " " + dayz + " " + hours + " " + minutes + " " + seconds);
}, 1000);
$('#currentDate').text(currentDate);
$('#futureDate').text(futureDate);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Current Date: <span id="currentDate"></span><br/>
Future Date: <span id="futureDate"></span><br/>
Time till: <span id="timeLeft"></span><br/>
我想這個問題是,你假設平均每月天都31時,而不是在30.41。 – zangarmarsh