1

在进行研究时,我很好奇为什么我的服务器在执行以下查询时显示不同的时间戳?

select current_timestamp(), UTC_TIMESTAMP(), convert_tz(UTC_TIMESTAMP(), 
@@session.time_zone,"+00:00") as timezone_utc, 
convert_tz(current_timestamp(), @@session.time_zone,"+00:00") as timezone_current

输出 :

current_timestamp() || UTC_TIMESTAMP() || timezone_utc || timezone_current

2015-04-02 03:01:25 || 2015-04-02 08:01:25 || 2015-04-02 13:01:25 || 2015-04-02 08:01:25
4

1 回答 1

1

因为你告诉它,它相信你告诉它的。convert_tz(UTC_TIMESTAMP(), @@session.time_zone,"+00:00")表示取当前 UTC 时间,假装它实际上是本地时间,然后通过添加本地时区偏移量的相反值将其转换为 UTC。这是一件荒谬的事情,并得到荒谬的结果。

于 2015-04-02T08:11:36.500 回答