简体   繁体   English

PHP和Mysql服务器之间的时区冲突

[英]Timezone conflict between PHP and Mysql server

I have an issue with the date creation. 我在创建日期时遇到问题。 The php server settings for timezone : by using the date_default_timezone_get() php function, refers to UTC whereas the MSQL query for timezone ie @@system_time_zone is referring to MST. 时区的php服务器设置:通过使用date_default_timezone_get()php函数,引用UTC,而对时区的MSQL查询(即@@ system_time_zone)则引用MST。 It is a shared server, so I will not be able to make changes in the my.conf file on the server. 这是一台共享服务器,因此我将无法在服务器上的my.conf文件中进行更改。

I want the date to be in UTC format, How do I go about making changes on the mysql server so that the Now() function and CURRENT_TIMESTAMP returns date values wrt UTC. 我希望日期为UTC格式,如何在mysql服务器上进行更改,以便Now()函数和CURRENT_TIMESTAMP返回带有UTC的日期值。

If I understood you right you can try and set a timezone per session from client code 如果我理解正确,则可以尝试通过客户端代码为每个会话设置时区

SET time_zone = timezone;

Depending on whether you have timezone info imported or not it may look like 根据您是否导入了时区信息,它可能看起来像

SET time_zone = 'Etc/UTC';

or 要么

SET time_zone = '+00:00';

Further reading: 进一步阅读:

尝试使用UTC_TIMESTAMP()而不是NOW()从mysql查询中获取日期,UTC_TIMESTAMP()将为您提供UTC日期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM