CakePHP 2时间格式

CakePHP 2时间格式,php,cakephp,datetime,timezone,cakephp-2.0,Php,Cakephp,Datetime,Timezone,Cakephp 2.0,我的时间格式有问题我有这样的代码 //in the core file it set to UTC debug(date_default_timezone_get()); $currentTime = time(); //UTC //CurrentTime in UTC debug(date('Y-m-d H:i:s',$currentTime)); $timepst = CakeTime::fo

我的时间格式有问题我有这样的代码

        //in the core file it set to UTC
        debug(date_default_timezone_get());
        $currentTime = time(); //UTC

        //CurrentTime in UTC
        debug(date('Y-m-d H:i:s',$currentTime));

        $timepst = CakeTime::format('Y-m-d H:i:s', $currentTime, null, 'PST');
        $timejst = CakeTime::format('Y-m-d H:i:s', $currentTime, null, 'JST');

        //I'm trying to convert back the time from PST to UTC using PST time
        $timeutc = CakeTime::format('Y-m-d H:i:s', strtotime($timepst), null, 'UTC');

        debug('PST : ' . $timepst);
        debug('JST : ' . $timejst);
        debug('UTC : ' . $timeutc);
结果是

'UTC'

'2012-10-05 19:44:50'

'PST : 2012-10-05 12:44:50'

'JST : 2012-10-06 04:44:50'

'UTC : 2012-10-05 12:44:50'
我的问题是,为什么使用PST时间转换回UTC不起作用? 有什么帮助吗


基本上,我想让用户根据自己的时区(用于日期输入)保存文章之类的内容,但我需要将其转换回UTC以保存在数据库中。

转换是基于服务器时区和用户时区之间的时差来完成的,该时差作为参数传递到CakeTime::format()。在第三次调用CaketTime::format()的示例代码中,您将用户时区作为UTC传递,服务器的时区也是UTC,因此不会发生时间更改。

是否有任何方法将用户时区作为设置的时区传递?而不是UTC(frm第三次呼叫)。我不明白你的问题。由于您在第三次呼叫中通过的时间是PST时区,因此您必须将服务器的时区设置为PST,以获得预期的结果。