1

我正在使用

$datetime = date_create()->format('Y-m-d H:i:s');

它正在插入我的数据库,但是 - 三个小时。例如,我的时间是晚上 9:30,它将插入 18:30。请帮忙。问候

4

2 回答 2

1

你可以试试这个,

    g   12-hour format of an hour without leading zeros (1 through 12)
    G   24-hour format of an hour without leading zeros (0 through 23)
    h   12-hour format of an hour with leading zeros    (01 through 12)
    H   24-hour format of an hour with leading zeros    (00 through 23)

    <?php echo date('Y-m-d H:i:s'');?> // 24 Hours format 

以下是时区转换器,

                PDT: America/Los_Angeles: <?php echo DatePNForServerTimeZone('D d M Y H:i:s A', 'America/Los_Angeles'); ?>                  

                EST: America/New_York: <?php echo DatePNForServerTimeZone('D d M Y H:i:s A', 'America/New_York');   ?>                  

                IST : Asia/Kolkata: <?php echo DatePNForServerTimeZone('D d M Y H:i:s A', 'Asia/Kolkata');  ?>                  

                <?php 
                    function DatePNForServerTimeZone($format='Y-m-d H:i:s', $Zone ='America/Los_Angeles'){

                        $utc = new DateTimeZone("UTC");
                        $new = new DateTimeZone($Zone);
                        $date = new DateTime(gmdate("m/d/Y H:i:s"), $utc);
                        $date->setTimezone($new);
                        return $date->format($format);

                    }

                ?>

参考: http: //php.net/manual/en/function.date.php

于 2013-11-12T04:51:39.040 回答
0

使用 date_default_timezone_set 如下

date_default_timezone_set('Asia/Dhaka');

检查手册

于 2013-11-12T04:47:10.997 回答