How to setup timezone xampp mysql and apache?

别来无恙 提交于 2019-12-03 19:42:31

问题


I am using XAMPP - PHP and MYSQL servers. When I tried to use following -

getRates(date('Y-m-d'));



function getRates($cDate)
{
$query = "SELECT * FROM randa WHERE date like '$cDate'" //it only worked at times.  
}

?>

Then I realized the date('Y-m-d') does not return the correct date. Went to php.ini and changed time zone. And is still returning the wrong date.

How can I fix this ? Thank you


回答1:


Try this

1) In httpd.conf (\xampp\apache\conf\httpd.conf) , add the following line:

SetEnv TZ Europe/Moscow

2) Edit php.ini (\xampp\php\php.ini) date.timezone value in [Date] section:

date.timezone = "Europe/Moscow"

3) In my.ini (\xampp\mysql\bin\my.ini) add or replace

default-time-zone = "Europe/Moscow"

Restart Apache and MySQL




回答2:


Please add this code on your top page.

date_default_timezone_set('America/Los_Angeles');

Search your country here http://php.net/manual/en/timezones.php




回答3:


Solved: but feeling stupid.

my local machine had the correct time however, time zone was incorrect. Changed the time zone and it worked. I don't understand why though. The time WAS CORRECT. Zone was not.




回答4:


MySQL stores datetime as [yyyy-mm-dd hh:mm:ss] at the UTC timezone. Your field in the db may be set up incorrectly but it may help if you post it's parameters. You shouldn't need to change settings in the conf or php.ini files. I suspect the difference between UTC and your timezone is making the query fail at certain times of the day because the UTC timestamp has passed into the next day. You may need to compensate your date prior to making the query by adding (or subtracting) the right amount of time so the datetime matches UTC. Something like this: getRates(date("Y-m-d h:i:sa",(yourtimestamp + (7 * 60 * 60)))); Or declare the timezone prior to the query: date_default_timezone_set("America/New_York");



来源:https://stackoverflow.com/questions/26269364/how-to-setup-timezone-xampp-mysql-and-apache

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