当我尝试从MySQL应用程序向表中插入值时,我看到Java出现了我认为意想不到的行为。我读了很多关于DATETIME的StackOverflow问答,但这似乎是一个完全不同的问题。
我的Java应用程序使用MyBatis和this DateTimeTypeHandler插入一个joda DateTime值2015-03-04T22:30:59.922Z。(我还修改了上面的代码以使用setTimestamp(int,Timestamp,Calendar)方法,但没有注意到结果的差异)。
我看到插入到表中的是值2015-03-04 14:30:59.922。我读到MySQL DATETIME使用服务器默认时区。我住在PDT时区,所以我希望值是2015-03-04 15:30:59.922 (即15:30而不是14:30)。
令人惊讶的是,在MySQL中似乎没有任何东西表明PDT时区。那么为什么我在表中的日期时间值是2015-03-04 14:30:59.922?
mysql> select @@global.time_zone; +--------------------+ | @@global.time_zone | +--------------------+ | UTC | +--------------------+ 1 row in set (0.06 sec)
mysql> select @@session.time_zone; +---------------------+ | @@session.time_zone | +---------------------+ | UTC | +---------------------+ 1 row in set (0.07 sec)
mysql> SELECT @@system_time_zone; +--------------------+ | @@system_time_zone | +--------------------+ | UTC | +--------------------+ 1 row in set (0.07 sec)
发布于 2015-05-29 03:31:10
2015年3月4日为标准时间,因此偏移量为-8小时:
UTC (Time Zone) Wednesday, March 4, 2015 at 10:30:00 PM UTC
Los Angeles (U.S.A. - California) Wednesday, March 4, 2015 at 2:30:00 PM PST UTC-8 hours 今天(2015年5月28日)为夏令时,因此偏移量为-7小时:
UTC (Time Zone) Thursday, May 28, 2015 at 10:30:00 PM UTC
Los Angeles (U.S.A. - California) Thursday, May 28, 2015 at 3:30:00 PM PDT UTC-7 hours https://stackoverflow.com/questions/30515380
复制相似问题