1. 日期与时间戳的转换
- 时间戳转为日期
from_unixtime(bigint unixtime[, stringformat])
- 日期转为时间戳
unix_timestamp(string date[, stringformat])
to_unix_timestamp(string date[, stringformat])
to_unix_timestamp 和unix_timestamp 都可以转化日期为时间戳,但据说前者效率更高。
select from_unixtime(1516723824,'yyyy-MM-dd HH:mm:ss')
select to_unix_timestamp('2021-01-05 12:32:41','yyyy-MM-dd HH:mm:ss')
select to_unix_timestamp('2021-01-05 12:32:41')
select unix_timestamp('2021-01-05 12:32:41','yyyy-MM-dd HH:mm:ss')
select unix_timestamp('2021-01-05 12:32:41')
2. 获取当前时间日期
select current_date()
select current_timestamp()
select unix_timestamp()
select from_unixtime(unix_timestamp(), 'yyyyMMdd HH:mm:ss')
3. 时间日期格式
select unix_timestamp