how to set default time zone in yii?

21,862

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.

  • 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'

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.

Share:
21,862
unknownbits
Author by

unknownbits

try to start it again

Updated on October 09, 2020

Comments

  • unknownbits
    unknownbits over 3 years

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

    date_default_timezone_set('Asia/Calcutta');
    

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

  • Mohammed H
    Mohammed H almost 9 years
    I think better to fix in php code. If you are working in a team, each member should change their php.ini. So you need to inform everyone. If you are fixing it in php, no need to inform anyone. Moreover, if you are hosting the web app in shared hosting, you may not have permission to change the timezone settings.
  • sensorario
    sensorario almost 9 years
    We are in 2015. Today there are teams that works in a single vagrant machine. All member of the team works inside the same machine.
  • sensorario
    sensorario almost 9 years
    I mean that configuration can be done one time for all. And all developer can upgrade the vagrant machine. If you fix php code, you need to fix all php code.
  • Mohammed H
    Mohammed H almost 9 years
    But In 2015 we are using version control system. So no need to fix in all php code :-P I don't know the vagrant machine.
  • sensorario
    sensorario almost 9 years
    Ok, every time you "buy" a machine, you have to install some software. Each time. But, ... you can also work with vagrant, create your "box" and then share your box "under version control system XD" with all your team member. You vagrant machine can replicate production machine. And every time production server need a change, you just need to update the vagrant box. 1 team member? 1000 Team members? ... just vagrant machine. Yo!
  • Saani
    Saani over 8 years
    What if I m not on localhost and still get the error?