2

仅在一台特定服务器上出现上述错误 - 而不是其他服务器。假设这是一个php版本问题。这是触发错误的代码:

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

最后一行导致了问题。关于如何解决它的任何想法?

4

1 回答 1

8

如果你的 PHP 版本低于 5.3,那么你可以使用这个类来使用函数“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' );

?>
于 2013-05-15T00:45:57.697 回答