Php 转换时间戳中的时区差异

Php 转换时间戳中的时区差异,php,sql,datetime,timestamp,unix-timestamp,Php,Sql,Datetime,Timestamp,Unix Timestamp,我找到了一个类,用于将时间戳转换为X时间。 它工作得很好,除了一个问题。我在太平洋时区,所以时间总是在8小时前,而实际上应该是2秒前 class Cokidoo_DateTime extends DateTime { protected $strings = array( 'y' => array('1 year ago', '%d years ago'), 'm' => array('1 month ago',

我找到了一个类,用于将时间戳转换为X时间。 它工作得很好,除了一个问题。我在太平洋时区,所以时间总是在8小时前,而实际上应该是2秒前

    class Cokidoo_DateTime extends DateTime {
        protected $strings = array(
            'y' => array('1 year ago', '%d years ago'),
            'm' => array('1 month ago', '%d months ago'),
            'd' => array('1 day ago', '%d days ago'),
            'h' => array('1 hour ago', '%d hours ago'),
            'i' => array('1 minute ago', '%d minutes ago'),
            's' => array('now', '%d secons ago'),
        );

        /**
         * Returns the difference from the current time in the format X time ago
         * @return string
         */
        public function __toString() {
            $now = new DateTime('now');
            $diff = $this->diff($now);

            foreach($this->strings as $key => $value){
                if( ($text = $this->getDiffText($key, $diff)) ){
                    return $text;
                }
            }
            return '';
        }

        /**
         * Try to construct the time diff text with the specified interval key
         * @param string $intervalKey A value of: [y,m,d,h,i,s]
         * @param DateInterval $diff
         * @return string|null
         */
        protected function getDiffText($intervalKey, $diff){
            $pluralKey = 1;
            $value = $diff->$intervalKey;
            if($value > 0){
                if($value < 2){
                    $pluralKey = 0;
                }
                return sprintf($this->strings[$intervalKey][$pluralKey], $value);
            }
            return null;
        }
    }
默认设置为当前_时间戳

如何修改我的方法以使其工作? 理想情况下,我希望这对每个人都是通用的,所以无论你在哪个时区,它都会根据新条目存在的时间显示X个时间之前

        $now = new DateTime('now');

请求当地时间。但你需要UTC时间。UTC作为构造函数的第二个参数。

时间戳是本地时间还是UTC?
        $now = new DateTime('now');