You can try like this,
date( "Y-m-d H:i:s", (strtotime($olddatetime." +1 hour")));
题
in php how do I add a hour to
$newdatetime = $olddatetime(strtotime("+1 hour"));
// this is the format of $olddatetime 0000-00-00 00:00:00
I already have the hour difference in the timezones I know its with the strtotime function but I couldn't get it formatted right to work
解决方案
You can try like this,
date( "Y-m-d H:i:s", (strtotime($olddatetime." +1 hour")));
其他提示
Try using DateTime
objects:
$newdatetime = new DateTime($olddatetime);
$newdatetime->modify('+1 hour');
echo $newdatetime->format('Y-m-d H:i:s'); // or whatever output format you want
Try to use following code,
$olddatetime = "2014-03-07 10:00:00"; // Requested format
$newdatetime = (strtotime($olddatetime."+1 hour")); // add one hour
$newdatetime = date("Y-m-d H:i:s", $newdatetime); // New date time
echo $newdatetime;exit; // Print it