如何在PHP中更改默认时区 [英] How to change default time zone in php
问题描述
我收到了一个用php和mysql构建的网站,但是编码器以UTC格式保留了默认时区,我如何将其更改为EDT,所以该站点中的所有控件现在都使用EDT time NOT UTC。我遍历了整个代码,编码器在某些地方调用了strttotime,但是我在任何地方都看不到时区,到处显示的时间来自包含带有strttotime的UNIX时间戳的数据库列。
i received a website built in php and mysql, but the coder left the default time zone in UTC format, how do i change that to EDT so all of the controls within the site now use EDT time NOT UTC. I've looked throughout the code and the coder calls strttotime in some places but i dont see timezone anywhere, the times that show up everywhere come from database columns containing UNIX timestamp with strttotime.
推荐答案
对于PHP:
date_default_timezone_set('America/New_York');
http://php.net/manual/en/function.date-default-timezone-set.php
这也可以在服务器的 php.ini
文件中进行配置。
This is also configurable in your server's php.ini
file.
对于MySQL,在 my.cnf
:
default_time_zone='America/New_York'
或对于单个会话,查询以下内容:
or for a single session, a query of:
SET time_zone = 'America/New_York';
这篇关于如何在PHP中更改默认时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!