php 如何在yii中设置默认时区?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17946131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:41:55  来源:igfitidea点击:

how to set default time zone in yii?

phpyiitimezone

提问by unknownbits

I want to set default time zone in my YII project.

我想在我的 YII 项目中设置默认时区。

date_default_timezone_set('Asia/Calcutta');

so, what will be the best location for it.where should I put this to make it default.

那么,它的最佳位置是什么。我应该把它放在哪里以使其成为默认值。

回答by

When someone is reffering to application property or application config it means "root" config variable, in this case timeZone.

当有人提到应用程序属性或应用程序配置时,它意味着“根”配置变量,在这种情况下timeZone

Config part:

配置部分:

<?php
// in protected/config/main.php
return array(
    'timeZone' => 'Asia/Calcutta'
    // Other configuration....
);

回答by sensorario

Pay attention: is not Yii or php stuff. You have to define date.timezone in your php.ini file. Now I'll give you some steps to fix this issue.

注意:不是 Yii 或 php 的东西。您必须在 php.ini 文件中定义 date.timezone。现在,我将为您提供一些解决此问题的步骤。

  • first of all create your own phpinfo.php file and put insite the php code

    phpinfo();

  • run this script and look for path of your php.ini file.

  • open php.ini, look for date.timezone string and set the value to (for example)

    date.timezone = 'Europe/Rome'

  • 首先创建您自己的 phpinfo.php 文件并将 php 代码放在现场

    phpinfo();

  • 运行此脚本并查找 php.ini 文件的路径。

  • 打开 php.ini,查找 date.timezone 字符串并将值设置为(例如)

    date.timezone = '欧洲/罗马'

Now you wont never get again that error. Why fix this stuff in php.ini and not in php code? Easy: if you fix php.ini files you do this stuff once for all your websites. If you fix this stuff in php code, you'll need to fix again and again each time you start a new project.

现在你不会再遇到那个错误了。为什么要在 php.ini 中而不是在 php 代码中修复这些东西?简单:如果你修复了 php.ini 文件,你就可以为所有网站做一次这些事情。如果你在 php 代码中修复这些东西,你每次开始一个新项目时都需要一次又一次地修复。

回答by Sankalp Singha

Put it In config/main.php This is the file that gets read first. Put it just before the return array ().

把它放在 config/main.php 这是最先读取的文件。把它放在返回数组 () 之前。