我要做的是在当前时间添加一定的时间,然后将其添加到数据库,但由于某种原因它只返回小时时间?
$nowtime = date("Y-m-d H:i:s");
if($time_selected==="wt-15")
{
$play_time = date('H:i:s', strtotime($nowtime . '+15 minutes'))+ " GMT ";
$time_minus = "-15 minutes";
} else if($time_selected==="wt-30") {
$play_time = date('H:i:s', strtotime($nowtime .'+30 minutes'))+ " GMT ";
$time_minus = "-30 minutes";
} else if($time_selected==="wt-45") {
$play_time = date('H:i:s', strtotime($nowtime .'+45 minutes'))+ " GMT ";
$time_minus = "-45 minutes";
} else {
$play_time = date('H:i:s', strtotime($nowtime .'+1 hour')) + " GMT ";
$time_minus = "-1 hour";
}
$game_data = array(
'username_1' => $username,
'amount' => $_POST['wamount'],
'console' => $console,
'pot' => $winner_pot,
'time_selected' => $time_minus,
'rules' => $_POST['gametype'],
'time_game' => $play_time
);
我将查询回显到页面上,这就是结果
INSERT INTO `gsessions` ( `username_1`, `amount`, `console`, `pot`, `time_selected`, `rules`, `time_game`) VALUES ('Aidan', '50', 'Xbox 360', '100', '-1 hour', 'gt-standard', '19')
19是它返回的时间,我怎么能以这种格式返回它#19; 19:15'对于数据库中的VARCHAR字段?
答案 0 :(得分:1)
+
不是PHP中的连接运算符; .
是。
更改如下所示的行:
$play_time = date('H:i:s', strtotime($nowtime .'+1 hour')) + " GMT ";
对此:
$play_time = date('H:i:s', strtotime($nowtime .'+1 hour')) . " GMT";
问题是(如果你好奇的话),就像你在做整数加法一样对待它。它将两个字符串拼写为整数,然后将它们一起添加。