简体   繁体   中英

Issues with MySQL (phpmyadmin) time zones

I have a website stored on a shared server and the timezone is set based on the operating system of the server, which is two hours ahead.

I changed my php.ini and tried:

SET time_zone='-7:00'
SET time_zone='Canada/Mountain'

In MySQL but it does not work. Is there a way around this? To override or set the timzone?

My hosting company support said I should run the "SET time_zone" at the start of every mysql session, but I dont understand what they mean and they are very vague about it.

You need to do it just after you connected with your database.

For EX (This is just example if you are using PDO you can change it accordingly):

    mysql_query("SET time_zone='-7:00'");

I would also like to mention here the +/- sign is essential — even for zero.

Also from Mysql docs :

"The current session time zone setting affects display and storage of time values that are zone-sensitive.This includes the values displayed by functions such as NOW() or CURTIME(), and values stored in and retrieved from TIMESTAMP columns.

The current time zone setting does not affect values displayed by functions such as UTC_TIMESTAMP() or values in DATE, TIME, or DATETIME columns."

Hope this help !

I had similar problems with time and date when i move from php4 to php5, all my time function stop work. Solution is to put date_default_timezone_set('America/Los_Angeles'); in first line of code.

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