【问题标题】:Echo if the date is 24 hours before the required date如果日期比所需日期早 24 小时,则回显
【发布时间】:2013-01-11 03:38:47
【问题描述】:

我不知道该在搜索栏中放什么,因为我不知道该怎么称呼它,如果我有重复的主题,那就太糟糕了。

我真的不知道该怎么说,但我举个例子。

假设 2013 年 1 月 20 日 09:30:00 有一个活动。今天的日期是 2013 年 1 月 11 日 15:25:00

我想在 2013 年 1 月 20 日的活动前一天回应一些事情。(活动前 24 小时

就好像在 2013 年 1 月 19 日,我将收到或回应一些应该提醒我明天是活动发生的事情。

好吧,我正在处理这段代码,但仍然感觉很不对劲。

$start_ts = strtotime("2013-01-10 20:15:00"); //
$now_ts = strtotime("now");
$result_ts = $start_ts - $now_ts;
$reminder = ( 60 * 24 ) * 60; // 24 hours period

if ($result_ts <= $reminder) {
    echo "Today's a date before the event day";
} else {
    echo "Event is already finished";
}

输出为:

它应该回显“事件已经完成

说实话,我在这里迷失了方向。希望你们帮助我,但会很高兴。

【问题讨论】:

    标签: php date datetime timestamp unix-timestamp


    【解决方案1】:

    这就是魔法:

    if ($result_ts <= $reminder && $result_ts > 0) { //blah blah }
    

    【讨论】:

    • 没想到它会起作用。谢谢!但是,我不明白。如果今天的日期是 2013 年 1 月 11 日,然后将 $start_ts 更改为 2013 年 1 月 12 日,它与今天的事件前一天相呼应,但如果我将其更改为 1 月 13 日、14 日、15 日左右,为什么它仍然有效?由于“$result_ts > 0”,它应该给出正值,对吗?日期大于 11。
    • 哦!我已经明白了。我试验了一下。不过非常感谢。你的帮助非常非常大。 :)
    猜你喜欢
    • 2014-04-20
    • 1970-01-01
    • 2012-12-12
    • 2015-04-18
    • 1970-01-01
    • 2021-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多