Where does PHP get it's DATE information from?

删除回忆录丶 提交于 2019-12-13 09:35:11

问题


I live in the UK and the current time is 02:30am on Monday 10th Feb 2014, however, my website is showing 02:30am Sunday 9th Feb 2014 - the day and date where the same before midnight so i am assuming a timezone difference. Can i set this to my own timezone ?

edit: Can i set this to the users' timezone?


回答1:


That doesn't look like a timezone issue since the date if off by a full 24 hours. But just in case it is, it is set in your php.ini, and of that is not set, it defaults to the server time zone.

You can set it in your php.ini file by setting date.timezone to be the timezone of your choosing.

date.timezone = Europe/London;

If you don't have access to the php.ini you can use date_default_timezone_set to set the timezone in your scripts.

date_default_timezone_set('Europe/London');



回答2:


You have two ways to define the timezone you want:

  1. date_default_timezone_set date_default_timezone_set('Asia/Manila');

  2. Modifying your php.ini: date.timezone = Asia/Manila




回答3:


In code, you can see what the default timezone is by calling date_default_timezone_get(). You can set it programatically using date_default_timezone_set(). The preferred way to do it though is to use the php.ini settings.




回答4:


I think you have to set the timezone preference in the php.ini file that initializes the PHP environment or if you don't have access to anything like that, you could look into http://www.php.net/manual/en/function.date-default-timezone-set.php



来源:https://stackoverflow.com/questions/21668157/where-does-php-get-its-date-information-from

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!