在PHP 5.3中将DateTime对象与另一个对象进行比较

You*_*eat 1 php datetime compare

好的,所以我正在制作一个基于文本的在线游戏,现在我已经完成了一个完成:

function....

    // I can't get this script to execute when I know the time has passed.

    $now = new DateTime("now", new DateTimeZone('UTC'));
    $row_date = new DateTime($row["due_date"], new DateTimeZone('UTC'));

    if ($row_date->format('Y-m-d H:i:s') <= $now->format('Y-m-d H:i:s')) 
    {
        mysql_query(".....")VALUES ("....")or die(mysql_error());
        mysql_query("DELETE FROM ......")or die(mysql_error());
    }
    else 
    {
        // The time has not come yet.
    }
Run Code Online (Sandbox Code Playgroud)

这个代码将使用jQuery的setInterval每10秒执行一次.

Kin*_*nch 11

DateTime 是比较的

if ($row_date <= new DateTime) { /* Do something */ }
Run Code Online (Sandbox Code Playgroud)