Carbon Php计时器(步进计数器)返回仅含NaN的iPhone



我对Carbon PHP有问题。我从后端收到一个date,并做了一个步进计数器。但step counter在电脑和安卓系统上运行良好。但在iPhone上,它给出了Nan。我该如何解决这个问题?

<script>
var c = new Date('{{ CarbonCarbon::createFromFormat('Y-m-d H:i:s', $productOfDay->expired_at) }}').getTime();
console.log(c); // iPhone returns NaN here
var mf = setInterval(function() {
var n = new Date().getTime();
var t = c - n;
var da = Math.floor(t / (1000 * 60 * 60 * 24));
var ho = Math.floor((t % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var mins = Math.floor((t % (1000 * 60 * 60)) / (1000 * 60));
var sec = Math.floor((t % (1000 * 60)) / 1000);
document.getElementById("days").innerHTML = da;
document.getElementById("hours").innerHTML = ho;
if (ho < 10) {
document.getElementById("hours").innerHTML = "0" + ho;
}
document.getElementById("mins").innerHTML = mins;
if (mins < 10) {
document.getElementById("mins").innerHTML = "0" + mins;
}
document.getElementById("secs").innerHTML = sec;
if (sec < 10) {
document.getElementById("secs").innerHTML = "0" + sec;
}
if (t < 0) {
clearInterval(mf);
document.getElementById("days").innerHTML = "";
document.getElementById("hours").innerHTML = "";
document.getElementById("mins").innerHTML = "";
document.getElementById("secs").innerHTML = "";
document.getElementById("end").innerHTML = "TIMES UP Please try new dates!!";
}   
}, 1000);
</script>

我解决了我的问题。我删除了carbon并使用了json_encode

const product = (<?= json_encode($productOfDay) ?>);
var b = new Date(product.expired_at).getTime();

相关内容

  • 没有找到相关文章

最新更新