PHP 将时间与未定义的时区进行比较
我需要比较时间,我使用变量来定义时区、当前时间和要比较的时间。
我正在使用此脚本根据用户选择执行某些操作。用户可以选择执行此操作的时间、日期和时区。
如果当前时间>或等于用户选择的这些操作应运行的时间。
所以我需要比较当前时间和用户选择的时间。当前时间由用户选择的时区给出。
这是我的代码。比较效果不太好。它认为与实际想法相反的事情......我需要帮助......可能不使用 php 5.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;
}
I need to compare times, I am using variables to define timezones, the current time and the time to be compared.
I am using this script to do certain actions based on what the user selects. The user can select a time when this action should be done, a date and a timezone.
If the current time is > or equal than the time selected by the user those action should run.
So I need to compare the current time and the time selected by the user. The current time is given by the timezone selected by the user.
This is the code I have. The comparison is not working fine. It thinks the oppposite thing than what should actually thinks... I need an help.. possibly not using php 5.3 or above. Better if functions are avaialbe from version 4 to 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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
数据库中的用户定义时间是否相对于同一时区。您可以尝试以下代码片段:
最好使用 Unix Time Stamp< 来保存用户定义的时间/a>.
If user defined time in database is relative to same timezone. you could try this snippet follow:
It would be better to save user defined time with Unix Time Stamp.