【发布时间】:2016-08-13 11:20:39
【问题描述】:
对于实时倒计时,我使用一些 php 变量并在 js 中回显它们,如下所示:
$expire_year = '2016'; // year
$expire_month = '8'; // month ( 8 = August)
$expire_day = '14'; // day (14th)
$expire_hour = '2'; // hour ( 1-24)
$expire_minutes = '12'; // minutes
我在 js 中使用它们,例如:
timestamp = new Date(<?php echo $expire_year; ?>, <?php echo $expire_month - 1; ?>, <?php echo $expire_day; ?>, <?php echo $expire_hour; ?>, <?php echo $expire_minutes; ?>),
这很好用!
我使用 php strtotime 来检查日期是否真的已经过期:
$quickpollexpiredate = strtotime("August 14, 2016 2:12"); // set an expiration date
因此,对于 js 中的倒数计时器和 php 中的检查,我必须使用 2 个不同的日期“结构”。
是否可以在 php 中进行检查,以便我只需将 5 个变量($expire_year、$expire_month...)与 strtotime() 或其他函数一起使用?
所以实际上我想要实现的是这样的(当然这是错误的,但我希望你能理解我想要实现的目标)
$quickpollexpiredate = strtotime($expire_year, $expire_month, $expire_day, $expire_hour, $expire_minutes); // set an expiration date
【问题讨论】:
-
我不太明白。您必须将
strtotime("August 14, 2016 2:12")转换为js 日期对吗? -
是的,我只想在php中使用这5个变量并用它设置
strtotime和new Date -
new Date(<?=strtotime("August 14, 2016 2:12")?>)
标签: javascript php date strtotime