简体   繁体   中英

PHP date() function gives the wrong time

 date('d-m-y h:i:s A')

The above code displays the correct date but the wrong time. It isn't off by hours either; even the minutes are off. I have set the default time zone in PHP using the function as well as in php.ini, set the date and time on my server, and restarted it. Any ideas why it still won't work? I'm running CentOS with Apache and PHP. All are the latest versions.

[Update] Looks like it's a problem with my system clock. It resets itself to some random time whenever I manually update it. I've tried disabling ntpd but it still does this, not sure why. I'm not sure if should close this question or open a new one.

[Another Update] I set the timezone in Linux and even went into WHM > Server Configuration > Server Time and set it to update the date and time. It said it successfully updated it and displays the correct date and time, but as soon as I refresh it or check it on the server it's back to this other date and time. I can't tell at this point if it is reverting back instantly or not being set at all without throwing errors.

If you use date_default_timezone_set it's work true. I've had the same problem.

date_default_timezone_set("Asia/Bangkok");

After much digging, I found out some VPS hosts don't let you change the time on your own VM, so I had to take out a support ticket and have them fix it. If anyone else is having similar issues then I'd suggest asking your host first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM