File tree Expand file tree Collapse file tree
mysql/src/main/java/biz/chenxu/tutorial Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments