Call to a member function format() on a non-object

Hi,I need some help of this fatal error " Call to a member function format() on a non-object",I don’t know how to solve this problem.please help me on this

here is my code



   $utc= DateTime::createFromFormat('ymdhis', $ucttime);
    $utctime= $utc->format('Y-m-d H:i:s');// error here.
    $localtime= new DateTime($utctime);
    $localtime->add(new DateInterval('PT8H'));
    $exacttime= $localtime->format('Y-m-d H:i:s');

  echo $exacttime;

Thank you in advance.

i get error if i have this kind of data 140609212856

So, DateTime has some funky error handling. You’ll have to call DateTime::getLastErrors() to find out what happened.

$ucttime = 140609212856;

$utc = DateTime::createFromFormat('ymdhis', $ucttime);
[COLOR="#FF0000"]if ($utc === false) {
    print_r(DateTime::getLastErrors());
}[/COLOR]
$utctime = $utc->format('Y-m-d H:i:s');// error here.
$localtime = new DateTime($utctime);
$localtime->add(new DateInterval('PT8H'));
$exacttime = $localtime->format('Y-m-d H:i:s');

echo $exacttime;

Hi this is the result

Array ( [warning_count] => 0 [warnings] => Array ( ) [error_count] => 1 [errors] => Array ( [6] => Hour can not be higher than 12 ) )