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::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 以将其保存在数据库中。

4

1 回答 1

0

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

于 2012-10-05T20:01:35.860 回答