使用 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
Getting timestamp using MySQL
提问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_TIMESTAMP
is 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;
回答by Proteux
just use NOW()
只需使用 NOW()
Full reference: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html
完整参考:http: //dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html