How to setup timezone xampp mysql and apache?

后端 未结 4 798
没有蜡笔的小新
没有蜡笔的小新 2021-01-01 04:32

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         


        
相关标签:
4条回答
  • 2021-01-01 04:50

    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

    0 讨论(0)
  • 2021-01-01 04:51

    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");

    0 讨论(0)
  • 2021-01-01 04:56

    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

    0 讨论(0)
  • 2021-01-01 05:09

    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.

    0 讨论(0)
提交回复
热议问题