我的服务器(Tomcat)位于北美,我的客户遍布全球不同地区。
我遇到了一个问题:
select time_stamp from table_name;
___________________
| time_stamp |
---------------------
|2015-08-26 20:03:30|
---------------------
现在是北美时间(MySQL需要服务器时间),但我的客户正在HTML页面中查看印度/美国的这个值。
如何将此值转换为我的客户当地时间。
答案 0 :(得分:0)
使用convert_tz函数。
看看这个:http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_convert-tz
mysql> SELECT CONVERT_TZ('2007-03-11 2:00:00','US/Eastern','US/Central');
+------------------------------------------------------------+
| CONVERT_TZ('2007-03-11 2:00:00','US/Eastern','US/Central') |
+------------------------------------------------------------+
| 2007-03-11 01:00:00 |
+------------------------------------------------------------+
mysql> SELECT CONVERT_TZ('2007-03-11 3:00:00','US/Eastern','US/Central');
+------------------------------------------------------------+
| CONVERT_TZ('2007-03-11 3:00:00','US/Eastern','US/Central') |
+------------------------------------------------------------+
| 2007-03-11 02:00:00 |
+------------------------------------------------------------+
支持文档:http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html并填充表格http://dev.mysql.com/downloads/timezones.html