swoft icon indicating copy to clipboard operation
swoft copied to clipboard

swoft 2 时区设置问题

Open jiancixiuxian opened this issue 3 years ago • 2 comments

swoft 2.0.9 在 .env 里面设置了 TIME_ZONE=Asia/Bangkok 在 bin/swoft 里面设置了 ini_set('date.timezone', 'Asia/Bangkok'); 在 php.ini 里也设置了时区 但都均为生效 请问下 我是少了 哪一步吗

jiancixiuxian avatar Apr 22 '21 11:04 jiancixiuxian

以解决 在 app/Application.php 处理

jiancixiuxian avatar Apr 22 '21 16:04 jiancixiuxian

你好,在swoft项目根目录的 app\Application.php 的 beforeInit 函数中设置即可,如下所示:

<?php declare(strict_types=1);
/**
 * This file is part of Swoft.
 *
 * @link     https://swoft.org
 * @document https://swoft.org/docs
 * @contact  [email protected]
 * @license  https://github.com/swoft-cloud/swoft/blob/master/LICENSE
 */

namespace App;

use Swoft\SwoftApplication;
use function date_default_timezone_set;

/**
 * Class Application
 *
 * @since 2.0
 */
class Application extends SwoftApplication
{
    protected function beforeInit(): void
    {
        parent::beforeInit();

        // you can init php setting.
        // 设置时区
        date_default_timezone_set('Asia/Shanghai');
    }

XuanYi2018 avatar Apr 30 '21 15:04 XuanYi2018