使用 MySQL 获取时间戳

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4411311/
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 17:57:56  来源:igfitidea点击:

Getting timestamp using MySQL

mysqltimestamp

提问by bsytKorbi

How can I get the current timestamp using a mysql query?

如何使用 mysql 查询获取当前时间戳?

回答by Brad Koch

Depends on which kind you're looking for.

取决于您要寻找哪种类型。

The current integer Unix Timestamp (1350517005) can be retrieved like so:

当前整数 Unix Timestamp ( 1350517005) 可以这样检索:

SELECT UNIX_TIMESTAMP();

MySQL often displays timestamps as date/time strings. To get one of those, these are your basic options (from the MySQL Date & Time reference):

MySQL 经常将时间戳显示为日期/时间字符串。要获得其中之一,这些是您的基本选项(来自 MySQL 日期和时间参考):

SELECT CURRENT_TIMESTAMP;
SELECT CURRENT_TIMESTAMP();
SELECT NOW();

回答by Alex

CURRENT_TIMESTAMPis standard SQL and works on SQL server, Oracle, MySQL, etc. You should try to keep to the standard as much as you can.

CURRENT_TIMESTAMP是标准 SQL,适用于 SQL 服务器、Oracle、MySQL 等。您应该尽量保持标准。

回答by Pablo Santa Cruz

Select current_timestamp;