Skip to content

Commit 5282735

Browse files
author
chenhuawei
committed
增加serverTimeZone参数及测试结果描述
1 parent 783fec8 commit 5282735

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

mysql/src/main/java/biz/chenxu/tutorial/MySQLTimeZone.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@ public class MySQLTimeZone {
1717
/**
1818
* 先以本地时区写入一条时间记录,然后分别以本地时区和UTC时区读取写入的时间
1919
* 再以UTC时区写入一条时间记录,然后分别以UTC时区和本地时区读取写入的时间
20+
*
21+
* 测试数据库时区
22+
* 'system_time_zone', 'CST'
23+
* 'time_zone', 'SYSTEM'
24+
* 数据库服务器时区
25+
* /etc/localtime -> /usr/share/zoneinfo/Asia/Shanghai
26+
* 本地(JVM)时区
27+
* Asia/Shanghai
28+
*
29+
* 测试结果
30+
* 本地(JVM)时区 数据库值 JDBC返回值
31+
* Asia/Shanghai 2018-03-27 07:00:17 2018-03-27 15:00:17
32+
* UTC 2018-03-27 07:00:17 2018-03-27 07:00:17
33+
*
34+
* UTC 2018-03-27 07:00:18 2018-03-27 07:00:18
35+
* Asia/Shanghai 2018-03-27 07:00:18 2018-03-27 15:00:18
36+
*
2037
* @param cmd
2138
*/
2239
public void run(CommandLine cmd) {
@@ -27,6 +44,7 @@ public void run(CommandLine cmd) {
2744
Config config = builder
2845
.characterEncoding("utf8")
2946
.useTimezone(true)
47+
.serverTimezone("UTC")
3048
.cacheDefaultTimezone(false) //Driver默认会缓存时区信息导致切换时区没有生效,这里为了测试所以告诉Driver不要缓存
3149
.build();
3250

0 commit comments

Comments
 (0)