P粉7694133552023-09-04 00:23:10
问题是您使用的是不带参数的 date() 函数,请尝试使用这个:
$dateTimeNow = date("Y-m-d H:i:s"); function dateTimeShift($dateTimeIn, $lengthNum, $lengthWord) { $shifted = date("Y-m-d H:i:s", strtotime($dateTimeIn." + $lengthNum $lengthWord")); $difference = strtotime($shifted)-strtotime($dateTimeIn); return $shifted . " <br> " . floor($difference/86400) . " days or " . floor($difference/3600) . " hours"; } echo dateTimeShift($dateTimeNow, "1", "day");
输出:
2023-01-04 09:57:31 <br> 1 days or 24 hours