PHP - How to get datetime string from DateTime object

时间:2016-04-04 16:27:37

标签: php datetime

I've made a DateTime object using

$currtime = DateTime::createFromFormat("YmdHi");

Is there a way to get a string or an integer, which contains, for example, 201604041825?

$currtime->modify("+2 hours");
$newtime = $currtime->format("YmdHi");

returned

$newtime = 2147483647

1 个答案:

答案 0 :(得分:1)

This will help you

$current_date_object= new DateTime();
$current_date_object->modify("+2 hours");
$current_date_string= $current_date_object->format("Y-m-d H:i:sO");