- 当前时间函数
(1)current_date
SELECT current_date() FROM t1 LIMIT 1 ;select unix_timestamp() FROM t1 LIMIT 1;
(2)current_timestamp
SELECT current_timestamp() FROM t1 LIMIT 1 ;
(3)current_time
SELECT current_time() FROM t1 LIMIT 1 ;
(4)unix_timestamp
select unix_timestamp() FROM t1 LIMIT 1;
2. 格式化时间字符串
(1)unix_timestamp() , to_unix_timestamp()
unix_timestamp() 函数除了可以返回当前时间戳 ,另外加上参数(“yyyy'-'MM'-'dd' 'HH':'mm':'ss')也可返回指定日期时间戳 这时用法和 to_unix_timestamp() 一致 如:
select unix_timestamp('2019-07-11 15:20:00') FROM t1 LIMIT 1;
SELECT TO_UNIX_TIMESTAMP("2019-07-11",'yyyy-MM-dd') FROM t1 LIMIT 1;
(2)from_unixtime() 传入int类型,默认返回 'yyyy'-'MM'-'dd' 'HH':'mm':'ss' 类型日期。
也可以在后面加一个字符串参数,指定返回格式如 'yyyy/MM/dd HH'
select from_unixtime(1562829600) FROM t1 LIMIT 1;