我搜索了很多链接,但到目前为止我找不到解决我的问题的方法。
我在 Go Daddy 上有一个虚拟主机,它为 PHP 和 MySQL 返回不同的时间:
我已经将我的 PHP 时区设置为:
date_default_timezone_set('America/Sao_Paulo');
有人知道调整MySQL时间的方法吗?
谢谢
我在此链接中找到了我的解决方案:
https://www.sitepoint.com/synchronize-php-mysql-timezone-configuration/
实际上,我同步了我的 PHP 和 MySQL 时区。这是代码:
define('TIMEZONE', 'America/Sao_Paulo');
date_default_timezone_set(TIMEZONE);
$now = new DateTime();
$mins = $now->getOffset() / 60;
$sgn = ($mins < 0 ? -1 : 1);
$mins = abs($mins);
$hrs = floor($mins / 60);
$mins -= $hrs * 60;
$offset = sprintf('%+d:%02d', $hrs*$sgn, $mins);
// I already have a connection function
$return = pdo_mysql("SET time_zone='$offset';");
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句