本文介绍了PHP 和 MySQL 的时差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我搜索了很多链接,但到目前为止我找不到解决我问题的方法.
I searched many links but so far I coudn`t find a solution to my problem.
我在 Go Daddy 上有一个虚拟主机,它返回 PHP 和 MySQL 的时间不同:
I have a web hosting on Go Daddy, and it is returning different times for PHP and MySQL:
- PHP 日期时间 =>13/02/2018 17:10:50
- MySQL 日期时间 =>13/02/2018 12:10:50
我已经将我的 PHP 时区设置为:
I've already set my PHP timezone to:
date_default_timezone_set('America/Sao_Paulo');有谁知道调整 MySQL 时间的方法吗?
Would anyone know a way to adjust the MySQL time?
谢谢
推荐答案我在此链接中找到了我的解决方案:
I found my solution at this link:
www.sitepoint/synchronize-php-mysql-timezone-configuration/
实际上,我同步了我的 PHP 和 MySQL 时区.代码如下:
Actually, I synchronized my PHP and MySQL timezones. Here's the code:
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';");更多推荐
PHP 和 MySQL 的时差
发布评论