方法1: from_unixtime+ unix_timestamp
--20210303转成2021-03-03
from_unixtime(unix_timestamp('20210303','yyyymmdd'),'yyyy-mm-dd')
--2021-03-03转成20210303
from_unixtime(unix_timestamp('2021-03-03','yyyy-mm-dd'),'yyyymmdd')
--UTC时间
from_unixtime(
(
unix_timestamp(
regexp_replace(regexp_replace('2021-03-03T09:24:41.892Z', 'T', ' '), 'Z', ' ')
)
) + 8 * 3600,
'yyyy-MM-dd HH:mm:ss'
)
方法2: substr + concat
--20210303转成2021-03-03
concat(substr('20210303',1,4),'-',substr('20210303',5,2),'-',substr('20210303',7,2))
--2021-03-03转成20210303
concat(substr('2021-03-03',1,4),substr('2021-03-03',6,2),substr('2021-03-03',9,2))