How do I change MySQL timezone?
2008-03-26 22:09
811 查看
However, there are ways for you to get results that are in your preferred timezone. First determine how many hours your desired timezone is off from MST. For example, EST is +2 hours. PST is -1 hour.
Knowing the time offset, you can replace all your SQL statements of
SELECT NOW();
with
SELECT DATE_ADD(NOW(), INTERVAL 2 HOUR);
which will give you an EST date result. For a result in PST, you would do:
SELECT DATE_SUB(NOW(), INTERVAL 1 HOUR);
If you are working with time in seconds instead of dates, then factor in the offset in seconds. Because there are 3600 seconds in an hour, and EST is 2 hours later than MST, the following converts timestamps from MST to EST:
SELECT unix_timestamp() + (3600 * 2);
SELECT FROM_UNIXTIME(UNIX_TIMESTAMP() + (3600 * 2));
See the MySQL Manual's Date and Time Functions for more information.
Depending on your application, you may also need to do one of the following (but not both):
1. Find every place in your code where a date or time is displayed to the browser and have a user defined function change it to add or subtract the appropriate number of hours before displaying it.
2. Find every place in your code where dates or times are input into your system and have a user defined function add or subtract the appropriate number of hours before storing it.
相关文章推荐
- How do I change MySQL timezone?
- How to Change the MySQL Time Zone on an Ubuntu Server
- how to change timezone
- How to Change Timezone in your Linux System
- mysql The server time zone value 异常
- Mysql错误:The server time zone value is unrecognized or represents more than one time zone
- Howto change runtime variables without restart MySQL Server
- Caused by: com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: The server time zone...
- How do I change the schedule for replication between two domain controllers in a site?
- 解决mysql java.sql.SQLException: The server time zone value‘XXXXXX' is unrecognized or represents...
- HowTo: Linux Server Change OR Setup The Timezone
- 修改MySQL的时区,涉及参数time_zone
- How to get current date time in SharePoint Site Time Zone
- mysql出现Unknown or incorrect time zone: 'NULL'
- How to change Mysql root password under linux ?
- mysql的time_zone问题。5.7
- 连接MySQL时区bug: The server time zone value '�й���ʱ��' is unrecognized or represents more
- Change Time zone
- How to change data dir of mysql?
- mysql The server time zone value 异常