我有一个问题:
我有一个coutdown计时器。我想计算今天和随机日期之间的差异。我的代码是:
<script type="application/javascript">
function doneHandler(result) {
alert('test')
}
var d2 = new Date();
var d1 = new Date("{{ a_data.a_promo[0].getEndDate()|date("Y-m-d H:i:s") }}");
var myCountdown1 = new Countdown({
time: (d1-d2) * 3,
width:300,
height:60,
rangeHi:"day",
style:"flip", // <- no comma on last item!,
onComplete : doneHandler
});
</script>
{{ a_data.a_promo[0].getEndDate()|date("Y-m-d H:i:s") }}
是2017-08-09 12:12:12
,但我得到的差异大约是14天,但真正的差异大约是47天。你能帮我吗 ? Thx提前和抱歉我的英语
答案 0 :(得分:1)
你可以像下面这样(javascript): -
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class="payverlink" href="exbronzeregistrationform.php">Continue to registration</a>
<button class="silverpac" onclick="silver()">Choose Plan silverpac</button>
<button class="bronzepac" onclick="bronze()">Choose Plan bronzepac</button>
&#13;
注意: - 现在将此var d2 = new Date();
var d1 = new Date("2017-08-09 12:12:12");
var timeDiff = Math.abs(d2.getTime() - d1.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
console.log(timeDiff);
console.log(diffDays);
或timeDiff
传递给diffDays
内的time: