这是我的脚本
var specialDate = "<?php echo trim(date('Y-m-d\TH:i:s',strtotime($time[1])));?>";
var countDownDate = new Date(specialDate).getTime();
var now = new Date().getTime();
// Find the distance between now an the count down date
var distance = countDownDate - now;
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);
var countdown = days + "d " + hours + "h " + minutes + "m " + seconds + "s ";
上述代码在除safari之外的所有浏览器上都运行良好。 谷歌搜索后我才知道我需要将其转换为iso 8601兼容为safari工作(目前它在safari浏览器iphone 6上显示nand nanh nanm nans错误)
答案 0 :(得分:0)
尝试更改以下内容:
var specialDate = "<?php echo trim(date('Y-m-d\TH:i:s',strtotime($time[1])));?>";
var countDownDate = new Date(specialDate).getTime();
要:
// echo php timestamp
var specialDate = <?php echo strtotime($time[1]);?>;
// multiply by 1000 for equivalent of `Date.getTime()`
var countDownDate = specialDate * 1000;