我試圖在我的表中設(shè)置一個條件,以便當(dāng)updated_at時間+幾分鐘的間隙(作為一種限制)小于當(dāng)前時間時出現(xiàn)提交按鈕,這存儲在變量$time中,其中Updated_at時間添加了$time_gap限制并轉(zhuǎn)換為日期格式進(jìn)行比較,但僅與$currenttime比較天數(shù),不計算月份或年份,因此取7月31日> 8月1日。時間變量的代碼在這里,我首先將時間戳轉(zhuǎn)換為 strtotime,這樣我就可以添加更多時間($tmt 是額外時間,$tmot 是 update_at + $tmt),以便稍后與 $currenttime 進(jìn)行比較。 $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);比較僅針對天數(shù)小時/分鐘/秒進(jìn)行,并且不檢查比較的月份和年份,我嘗試使用 switch case 而不是 if elseif,但問題仍然相同。
1 回答

楊__羊羊
TA貢獻(xiàn)1943條經(jīng)驗(yàn) 獲得超7個贊
通過將最終日期再次轉(zhuǎn)換為 strtotime 來修復(fù),因此對于上述代碼:
$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 關(guān)注
- 195 瀏覽
添加回答
舉報
0/150
提交
取消