一、时间戳函数
-- 日期转时间戳:从1970-01-01 00:00:00 UTC到指定时间的秒数
select unix_timestamp(); -- 查询当前时间的时间戳,返回:1573453747
select unix_timestamp('2019-11-11 14:22:32'); -- 查询指定时间的时间戳,返回:1573453352 (若转换失败返回0)
select unix_timestamp('2019-11-11 14:22:32','yyyy-MM-dd HH:mm:ss'); -- 转换指定格式时间的时间戳,返回:1573453352
select unix_timestamp('20191111 14:22:31','yyyyMMdd HH:mm:ss'); -- 转换指定格式时间的时间戳,返回:1573453352
-- 时间戳转日期
select from_unixtime(1573453352);-- 查询指定时间戳的时间,默认格式yyyy-MM-dd HH:mm:ss,返回:2019-11-11 14:22:32
select from_unixtime(1573453352,'yyyyMMdd');-- 查询指定时间戳的时间,转换成指定格式,返回:20191111
select from_unixtime(1573453352,'yyyy-MM-dd HH:mm:ss');-- 查询指定时间戳的时间,转换成指定格式,返回:2019-11-11 14:22:32
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss');-- 查询系统当前时间戳的时间,转换成指定格式,返回:2019-11-11 15:55:22
二、获取当前日期
2.1、取得当前日期
select current_date();
2.2、取得当前日期时间
select current
-- 日期转时间戳:从1970-01-01 00:00:00 UTC到指定时间的秒数
select unix_timestamp(); -- 查询当前时间的时间戳,返回:1573453747
select unix_timestamp('2019-11-11 14:22:32'); -- 查询指定时间的时间戳,返回:1573453352 (若转换失败返回0)
select unix_timestamp('2019-11-11 14:22:32','yyyy-MM-dd HH:mm:ss');
select unix_timestamp('20191111 14:22:31','yyyyMMdd HH:mm:ss'); -- 转换指定格式时间的时间戳,返回:1573453352
-- 时间戳转日期
select from_unixtime(1573453352);-- 查询指定时间戳的时间,默认格式yyyy-MM-dd HH:mm:ss,返回:2019-11-11 14:22:32
select from_unixtime(1573453352,'yyyyMMdd');-- 查询指定时间戳的时间,转换成指定格式,返回:20191111
select from_unixtime(1573453352,'yyyy-MM-dd HH:mm:ss');-- 查询指定时间戳的时间,转换成指定格式,返回:2019-11-11 14:22:32
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss');-- 查询系统当前时间戳的时间,转换成指定格式,返回:2019-11-11 15:55:22
二、获取当前日期
2.1、取得当前日期
select current_date();
2.2、取得当前日期时间
select current
