我想弄清楚为什么我得错了,这是我的代码:
date_default_timezone_set("Europe/Amsterdam"); //Use the time of amsterdam
$date = new DateTime();
$date->modify("+".$tijd." minutes"); //Add the time in minutes to current time.
$datum = $date->format('Y-m-d H:i:s');
所以当$ tijd设置为10时,$ datum返回:2015-02-28 14:49:00 但在阿姆斯特丹,时间是14:10(此时此刻)。所以应该给出像2015-02-28 14:20:00这样的东西。
所以我做错了什么,因为这有点奇怪, 提前谢谢!
编辑:这是我的完整代码: 公共职能监狱($ tijd,$ id){
date_default_timezone_set("Europe/Amsterdam"); //Use the time of amsterdam
$date = new DateTime();
$date->modify("+".$tijd." minutes"); //Add the time in minutes to current time.
$datum = $date->format('Y-m-d H:i:s');
$conn = $this->conn;
$jail = $conn->prepare('UPDATE gebruikers
SET jail = :jail
WHERE id = :id');
$uitvoeren = $jail->execute(array(
':jail' => $datum,
':id' => $id));
if($uitvoeren){
return true;
} else {
return false;
}
}
然后在另一个PHP文件中:
$user = new user;
$tijd = 10;
$id = 1;
$gevangenis = $user->jail($tijd, $id);
if($gevangenis){
echo 'Gelukt!';
} else {
echo 'Mislukt!';
}