我用jQuery在datetime值之间写倒计时。但是这段代码没有打印任何页面。日期时间值$_endDateTime
和$_startDateTime
来自2017-04-30 23:55:32
格式的包含页面。
<!--
Creator: Ahmet ÇELİKEZER
Date: 30.04.2017
Variables Needed: $_endDateTime , $_startDateTime
-->
<?php
$dif_int = strtotime($_endDateTime) - strtotime($_startDateTime); //Diffrance between dates as interval
?>
<script>
$(function(){
var secLeft=<?php echo $dif_int; ?>;
var minLeft=0;
var hourLeft=0;
var dayLeft=0;
$.countBack=function()
{
if(secLeft>1)
{
secLeft--;
//Split Days,Hours,Minutes,Seconds
/*
1Day=86400 Sec
1Hour=3600 Sec
1Minute=60 Sec
1Second=1 Sec
*/
if(secLeft>86400)
{
dayLeft=secLeft / 86400;
secLeft=secLeft % 86400;
}
if(secLeft>3600)
{
hourLeft=secLeft / 3600;
secLeft=secLeft % 3600;
}
if(secLeft>60)
{
minLeft=secLeft / 60;
secLeft=secLeft % 60;
}
$("#printTime").Text(dayLeft+" Gün "+hourLeft+" Saat "+minLeft+" Dakika "+secLeft+" Saniye");
}
else {
{
//Time Ended
}
}
}
setInterval("$.countBack()",1000);
})
</script>
<p id="printTime"></p>