PHP将时间与未定义的时区进行比较

PHP将时间与未定义的时区进行比较,php,time,compare,Php,Time,Compare,我需要比较时间,我使用变量来定义时区、当前时间和要比较的时间 我使用这个脚本根据用户的选择执行某些操作。用户可以选择执行此操作的时间、日期和时区 如果当前时间大于或等于用户选择的时间,则应运行这些操作 所以我需要比较当前时间和用户选择的时间。当前时间由用户选择的时区给出 这是我的密码。这种比较并不奏效。它认为事情比实际应该想的更有利。。。我需要帮助。。可能不使用PHP5.3或更高版本。如果从版本4到版本5都有功能,效果会更好 date_default_timezone_set($TimeZone

我需要比较时间,我使用变量来定义时区、当前时间和要比较的时间

我使用这个脚本根据用户的选择执行某些操作。用户可以选择执行此操作的时间、日期和时区

如果当前时间大于或等于用户选择的时间,则应运行这些操作

所以我需要比较当前时间和用户选择的时间。当前时间由用户选择的时区给出

这是我的密码。这种比较并不奏效。它认为事情比实际应该想的更有利。。。我需要帮助。。可能不使用PHP5.3或更高版本。如果从版本4到版本5都有功能,效果会更好

date_default_timezone_set($TimeZone); //all the possible php timezones available can be choosen by the user
$todaydate = date('Y-m-d');
$time_now=mktime(date('G'),date('i'),date('s'));
$NowisTime=date('G:i:s',$time_now); //the time given by the selected timezone above
$time = $ris['Time']; //the time defined by the user in the DB
if($NowisTime >= $time){
DO THE ACTIONS
}else{
exit;

}

若数据库中的用户定义时间相对于同一时区。您可以尝试以下代码段:

$dateTimeZone = new DateTimeZone("Asia/Chongqing");
$localTime = new DateTime("now", $dateTimeZone);
$definedTime = new DateTime("2011-05-29 10:00:00", $dateTimeZone);
if ($localTime >= $definedTime) {
    echo "It is about time.";
} else {
    // do nothing.
}
更好的做法是通过使用来节省用户定义的时间