这在 PHP 中非常有效
date_default_timezone_set('my/timezone');
$actualDate = date('Y-m-d');
现在做查询时,我喜欢做
INSERT INTO articles (title, insert_date) VALUES ('My Title', now())
问题是 MySQL 中的 now()
与在 PHP 中计算的结果不同(因此与设置的时区不同)。
有没有办法,比如 SQL 查询,来设置 MySQL 的默认时区?
谢谢
最佳答案
http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html
If you have the SUPER privilege, you can set the global server time zone value at runtime with this statement:
mysql> SET GLOBAL time_zone = timezone;
Per-connection time zones. Each client that connects has its own time zone setting, given by the session time_zone variable. Initially, the session variable takes its value from the global time_zone variable, but the client can change its own time zone with this statement:
mysql> SET time_zone = timezone;
关于php - 在 MySQL 中是否有等效于 PHP 的 `date_default_timezone_set()` 的东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/896305/