Mysql 函数使用记录(三)——UNIX_TIMESTAMP() 、UNIX_TIMESTAMP(date)
参考资料:https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_unix-timestamp
UNIX_TIMESTAMP() :returns a Unix timestamp (seconds since '1970-01-01 00:00:00'
UTC). ——自'1970-01-01 00:00:00'的到当前时间的秒数差
例:
SELECT UNIX_TIMESTAMP(); ====> 1507520072
UNIX_TIMESTAMP(date) : it returns the value of the argument as seconds since '1970-01-01 00:00:00'
UTC. ——自'1970-01-01 00:00:00'与指定时间的秒数差
1>.The date
argument may be a DATE
, DATETIME
, or TIMESTAMP
string, or a number in YYMMDD
, YYMMDDHHMMSS
, YYYYMMDD
, or YYYYMMDDHHMMSS
format.
其中date可以是一个DATE,DATETIME或者TIMESTAMP的字符串,也可以是YYMMDD,YYMMDDHHMMSS,YYYYMMDD或YYYYMMDDHHMMSS格式的数字。
例:
SELECT UNIX_TIMESTAMP('2017-10-8 08:08:08'); ====> 1507421288
SELECT UNIX_TIMESTAMP(CURRENT_DATE()); ====> 1507478400
SELECT UNIX_TIMESTAMP(NOW()); ====> 1507520319
注:CURRENT_DATE ()的返回值是一个DATE字符串格式;NOW()的返回值是一个DATETIME字符串格式