在 MySQL 中获取当前 UTC 时间的 unix 时间戳的最佳方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17768426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:14:32  来源:igfitidea点击:

Best way to get unix timestamp for current UTC time in MySQL

mysqlmysql-workbench

提问by littlejedi

I've been trying to use the following in mySQL to create a unix stamp for current UTC time

我一直在尝试在 mySQL 中使用以下内容为当前 UTC 时间创建一个 unix 戳

UNIX_TIMESTAMP(UTC_TIMESTAMP())

When I execute the query and get the result, it seems like mySQL is doing UTC conversation twice.

当我执行查询并获得结果时,似乎 mySQL 进行了两次 UTC 对话。

Eg. local time 9:07PM

Query above returned: 1374390482, which is next day 07:08:02 GMT, which is correct,

上面的查询返回: 1374390482,这是第二天07:08:02 GMT,这是正确的,

However, UNIX_TIMESTAMP(LOCALTIMESTAMP())returns:

但是,UNIX_TIMESTAMP(LOCALTIMESTAMP())返回:

1374372551 02:09:11 GMT

which is the correct UTC unix timestamp.

这是正确的 UTC unix 时间戳。

So UNIX_TIMESTAMPautomatically translates the date object's timezone to UTC (regardless if it's already UTC or not?)

所以UNIX_TIMESTAMP自动将日期对象的时区转换为 UTC(无论它是否已经是 UTC?)

Is there a better way or a single command just to get a UTC unix timestamp in mySQL?

有没有更好的方法或单个命令来在 mySQL 中获取 UTC unix 时间戳?