SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,154
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post 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

    PHP 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.

  2. #2
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,154
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    i get error if i have this kind of data 140609212856

  3. #3
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,313
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    So, DateTime has some funky error handling. You'll have to call DateTime::getLastErrors() to find out what happened.

    Code:
    $ucttime = 140609212856;
    
    $utc = DateTime::createFromFormat('ymdhis', $ucttime);
    if ($utc === false) {
        print_r(DateTime::getLastErrors());
    }
    $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;
    "First make it work. Then make it better."

  4. #4
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,154
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    So, DateTime has some funky error handling. You'll have to call DateTime::getLastErrors() to find out what happened.

    Code:
    $ucttime = 140609212856;
    
    $utc = DateTime::createFromFormat('ymdhis', $ucttime);
    if ($utc === false) {
        print_r(DateTime::getLastErrors());
    }
    $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 ) )


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •