问题
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:
date_default_timezone_set
date_default_timezone_set('Asia/Manila');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