我试图在我的表中设置一个条件,以便当updated_at时间+几分钟的间隙(作为一种限制)小于当前时间时出现提交按钮,这存储在变量$time中,其中Updated_at时间添加了$time_gap限制并转换为日期格式进行比较,但仅与$currenttime比较天数,不计算月份或年份,因此取7月31日> 8月1日。时间变量的代码在这里,我首先将时间戳转换为 strtotime,这样我就可以添加更多时间($tmt 是额外时间,$tmot 是 update_at + $tmt),以便稍后与 $currenttime 进行比较。 $timestamps = userData::select('updated_at')->where('username',$username)->get(); foreach ($timestamps as $timestamp){ $timestamp = $timestamp->updated_at; } $timestamp = strtotime($timestamp); $currentstamp = now(); $currentstamp = strtotime($currentstamp); $currenttime = date("Y/m/d H:i:s", $currentstamp); $timegaps = division::select('time_gap')->where('id',$userdiv)->get(); foreach ($timegaps as $timegap){ $timegap = $timegap->time_gap; } $tmt = $timegap * 60 * 1; $tmot = $timestamp + $tmt; $time= date("Y/m/d H:i:s", $tmot);比较仅针对天数小时/分钟/秒进行,并且不检查比较的月份和年份,我尝试使用 switch case 而不是 if elseif,但问题仍然相同。
1 回答
杨__羊羊
TA贡献1943条经验 获得超7个赞
通过将最终日期再次转换为 strtotime 来修复,因此对于上述代码:
$currenttime = date("Y/m/d H:i:s", $currentstamp);
$timegaps = division::select('time_gap')->where('id',$userdiv)->get();
foreach ($timegaps as $timegap){
$timegap = $timegap->time_gap; }
$tmt = $timegap * 60 * 1; $tmot = $timestamp + $tmt; $time= date("Y/m/d H:i:s", $tmot);
$currenttime = strtotime($currenttime);
$time = strtotime($time)
- 1 回答
- 0 关注
- 137 浏览
添加回答
举报
0/150
提交
取消