倒数计时器未显示



我试图用php和js创建一个倒计时。我现在正在学习js和php,所以我想尝试将这两者结合起来,制作一个包含天、小时、分钟和秒的倒计时。这段代码的结果只告诉我直到它运行,但没有告诉我还有多少时间,所以倒计时本身不起作用。有人能帮忙吗?

<?php 
$date = date('2022-02-26');
$time = date('23:59:59');
$date_today = $date . ' ' . $time;
echo "it will run till" .$date_today;
?>
<script type="text/javascript">
//set the date we are counting to
var count_id = "<?php echo $date_today; ?>";
var countDownDate = new Date(count_id).getTime();
//update countdown every second
var x = setInterval(function(){
//get today's date and time
var now = new date().getTime();
//find the distance between now and countdown date
var distance = countDownDate - now;
//time calculations for days, hours, minutes and seconds
var days = Math.floor(distance/(1000 * 60 * 60 * 24));
var hours = Math.floor((distance%(1000*60*60*24))/(1000*60*60));
var minutes = Math.floor((distance%(1000*60*60))/(1000*60));
var seconds = Math.floor((distance%(1000*60))/1000);
// output the results in an elemtwith id="demo"
document.getElementById("demo").innerHTML = days + "d " + hours + "h " + 
minutes + "m " + seconds + "s ";
// If the countdown over, write some text
if(distance<0){
clearInterval(x);
document.getElementById("demo").innerHTML="Expired"
}
},1000);
</script><?php
echo '<p id="demo" style="font-size:30px;"></p>';
?>
var now = new date().getTime();

拼写错误,应该是

var now = new Date().getTime();

现在它工作

最新更新