设置MySQL的时区(Setting timezone for MySQL)

我使用PHP来设置网站的当前时区:

date_default_timezone_set('America/New_York');

我怎么能同时为mysql设置相同的时区,这样当我使用NOW()时它会使用在php中设置的时区?

Im using php to set the current timezone for a site:

date_default_timezone_set('America/New_York');

How could I, at the same time, set the same time zone for mysql so that when I use NOW() it uses the timezone set in php?

最满意答案

别。

最佳做法是将UTC存储在数据库中。

Don't.

The best practice is to store UTC in the database.

设置MySQL的时区(Setting timezone for MySQL)

我使用PHP来设置网站的当前时区:

date_default_timezone_set('America/New_York');

我怎么能同时为mysql设置相同的时区,这样当我使用NOW()时它会使用在php中设置的时区?

Im using php to set the current timezone for a site:

date_default_timezone_set('America/New_York');

How could I, at the same time, set the same time zone for mysql so that when I use NOW() it uses the timezone set in php?

最满意答案

别。

最佳做法是将UTC存储在数据库中。

Don't.

The best practice is to store UTC in the database.