SELECT UTC_TIMESTAMP() 如何返回 -10:00 UTC?
要么是我太蠢了,要么是这里出了什么问题。
我有两个 SQL Server,一个位于我的本地计算机上(当地时间 +2 GMT),另一个位于其他位置(NOW()
似乎返回 +8 GMT),我通过 phpMyAdmin 访问它。我有一个包含 DATETIME
列的表。我想
存储当前的GMT/UTC时间,然后再次显示,仍为GMT/UTC时间。
最初我存储了 DATE_SUB(NOW(), INTERVAL 8 HOUR)
,效果很好。然而,后来我读到了 UTC_TIMESTAMP() 并更喜欢它,因为它更短并且 MySQL 手册
甚至说:
“当前时区设置不会影响函数显示的值 例如 UTC_TIMESTAMP() 或 DATE、TIME 或 DATETIME 列中的值。”
太完美了,不是吗?除非不是。
让我们假设当前 GMT 是 2010-02-18 17:18:17 (我什至加倍 在我的本地(+2)服务器上与英国的某人进行了检查
,我得到以下查询的结果:
SELECT NOW(); 2010-02-18 19:18:17
SELECT UTC_TIMESTAMP(); 2010-02-18 17:18:17
在我的在线服务器上我得到:
SELECT NOW(); 2010-02-19 01:18:17
SELECT UTC_TIMESTAMP(); 2010-02-19 07:18:17 (WHY?!)
我是吗?缺少什么?!
Either I'm being stupid or something's wrong here.
I have two SQL Servers, the one is on my local machine (local time +2 GMT) and the other is somewhere else (NOW()
seems to return +8 GMT)and I access it through phpMyAdmin. I have a table that has a DATETIME
column. I'm trying
to store the current GMT/UTC time and then display it again, still as GMT/UTC time.
Originally I stored DATE_SUB(NOW(), INTERVAL 8 HOUR)
which worked just fine. However, then I read about UTC_TIMESTAMP()
and liked it more, as it was shorter and the MySQL manual
even said :
"The current time zone setting does not affect values displayed by functions
such as UTC_TIMESTAMP() or values in DATE, TIME, or DATETIME columns."
So perfect right? Except no.
Let's assume Current GMT is 2010-02-18 17:18:17 (I even double checked it with someone in Britain).
On my local (+2) server, I get the following results for the following queries:
SELECT NOW(); 2010-02-18 19:18:17
SELECT UTC_TIMESTAMP(); 2010-02-18 17:18:17
On my online server I get:
SELECT NOW(); 2010-02-19 01:18:17
SELECT UTC_TIMESTAMP(); 2010-02-19 07:18:17 (WHY?!)
Am I missing something?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能是因为在线服务器上的时钟错误?
尝试运行此:
并查看它返回哪个区域以及它是否匹配差异。
Probably because the clock are wrong on the online server?
Try running this:
and see which zone does it return and does it match the difference.