du21064 2016-07-13 07:29
浏览 60
已采纳

在PHP中添加小时到日期和时间会产生错误的输出

$datetime = Carbon::now()
$datetime = date($datetime);
$date = strtotime($datetime);
$date = strtotime($datetime);$dispatchDateTime = date("Y-m-d H:m:s", strtotime("+2 hours", $date));

Is this correct.. actully i am gettig wrong output. for any time it just give time like 2016-07-13 14:07:43 or 2016-07-13 13:07:43 time

  • 写回答

2条回答 默认 最新

  • dongyuan1902 2016-07-13 07:56
    关注
    $date = new DateTime('now');
    $twoHoursLater = $date->add(DateInterval::createFromDateString('+2 hours'));
    

    Hope this helps.
    Best Regards,
    M.I.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?