The date string you're passing is not supported by the DateTime parser. You must create a DateTime object by using createFromFormat. This method allows you to specify the custom format when creating a new DateTime object:
$my_dt = DateTime::createFromFormat('m-d-Y H:i:s', $token_created_at);
If you're still getting an error that means that your $token_created_at
is not in the format you specified:
$now = date('m-d-Y H:i:s'); //string(19) "06-28-2014 15:00:47"
var_dump(DateTime::createFromFormat('m-d-Y H:i:s', $now));
object(DateTime)#1 (3) {
["date"]=>
string(19) "2014-06-28 15:00:47"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/Berlin"
}
Edit
I see your problem - the format string has a space after s
. The format strings must match exactly:
$my_dt = DateTime::createFromFormat('m-d-Y H:i:s ', $token_created_at);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…