PHP 和 MySQL 的时差

编程入门 行业动态 更新时间:2024-10-28 02:30:08
本文介绍了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 的时差

本文发布于:2023-11-22 03:04:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1615729.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时差   PHP   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!