php - Fatal error: Call to undefined method DateTime::setTimestamp() -


getting above error on 1 particular server - not other servers. assuming it's php version issue. here code that's triggering error:

//get time interval     static function get_interval($now, $post_time){         $datetime1 = new datetime();         $datetime1->settimestamp($now); 

the last line causing problem. ideas on how around it?

if php version lower 5.3 can use class able use functions "settimestamp" , "gettimestamp":

<?php  class mydatetime extends datetime {     public function settimestamp( $timestamp )     {         $date = getdate( ( int ) $timestamp );         $this->setdate( $date['year'] , $date['mon'] , $date['mday'] );         $this->settime( $date['hours'] , $date['minutes'] , $date['seconds'] );     }      public function gettimestamp()     {         return $this->format( 'u' );     } }  $date = new mydatetime(); $date->settimestamp( $sometimestamp );  echo $date->format( 'd/m/y h:i:s' );  ?> 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -