我需要将额外的 24 小时添加到我的默认时间并存储在数据库中,例如开始时间 = 默认时间,结束时间 = 开始时间 + 24 小时。我已经尝试过这种方式。听到的是代码。<?phpdate_default_timezone_set("Asia/Colombo");$time = date("H:i:s");$validtime = '24:00:00';$endtime = strtotime($time + $validtime);echo date('H:i:s', $endtime);$bookname= $_GET['id'];$link=mysqli_query($conn, "update reserve_table set username='$_SESSION[username]', bookname='$bookname', reservetime='$time', endtime='$endtime'");?>并弹出这个错误注意:在第 33 行的 /opt/lampp/htdocs/Lowa/student/reserve.php 中遇到格式不正确的数值注意:第 33 行 05:30:00 在 /opt/lampp/htdocs/Lowa/student/reserve.php 中遇到格式不正确的数值
1 回答
呼如林
TA贡献1798条经验 获得超3个赞
PHP 无法在'24:00:00'格式中添加日期。这是一个字符串,而不是一个数字或“时间”的东西。当时间以秒为单位表示时,您可以添加时间。所以这将起作用:
// get time in seconds as an integer
$time = time();
// show it in seconds and formated
echo "In seconds: $time formated: " . date("Y-m-d H:i:s", $time);
// add a day
echo "<br>Add a day.<br>";
$time += 24 * 60 * 60;
// show it in seconds and formated
echo "In seconds: $time formated: " . date("Y-m-d H:i:s", $time);
time()以秒为单位返回当前时间。然后我们添加一整天的时间并将其转换为您需要的格式。
- 1 回答
- 0 关注
- 208 浏览
添加回答
举报
0/150
提交
取消