【发布时间】:2011-12-10 00:17:50
【问题描述】:
好的,我正在制作一个基于文本的在线游戏,但我现在卡在完成时:
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.
}
这段代码将使用 jQuery 的 setInterval 每 10 秒执行一次。
【问题讨论】:
-
对于新的
DateTime对象,默认时区是UTC,不是吗? (因此您不必也传递 DateTimeZone 对象,但请确保。)