【发布时间】:2017-08-14 17:57:52
【问题描述】:
我正在使用 ACF 字段来允许客户端内容管理他们下一个事件的倒计时我在桌面版本上使用 JS 翻转时钟,但由于它没有响应,我决定使用日期差异来回显移动天数。
该网站目前位于theindustrialproject.co.uk
我目前的代码是这样的:
<?php
$date1 = date_create(date());
$date2 = date_create(the_field('mobile_date'));
$diff = date_diff($date1,$date2);
$difference = $diff;
if ($difference < 0) { $difference = 0; }
echo '<span class="countdown-mobile">'. floor($difference/60/60/24)."</span><br />";
if ($difference == 1) { echo "<p>Day</p>"; }
else { echo "<p>Days</p>"; }
?>
但它总是返回0。作为参考,我从here中提取了代码
【问题讨论】:
-
date_diff不返回数字,而是返回DateIntervalobject。你有没有检查过$difference在你强制它为 0 的 if 语句之前和之后的值?
标签: php wordpress advanced-custom-fields