时间戳转换使用函数from_unixtime,from_unixtime中格式使用hh时为12小时制,使用HH时为24小时制,不写格式是,默认为24小时制;
Spark 官方文档如下:
https://spark.apache.org/docs/latest/api/sql/#from_unixtime
中文翻译:
示例如下:
select
start_time,
end_time,
from_unixtime(end_time,'yyyy-MM-dd hh:mm:ss') 12小时制格式,
from_unixtime(end_time,'yyyy-MM-dd HH:mm:ss') 24小时制格式,
from_unixtime(end_time) 默认24小时制格式
from(
select
'2021-04-09 13:20:01' start_time,
'1617974401' end_time
from table_name) t;
start_time | end_time | 12小时制格式 | 24小时制格式 | 默认24小时制格式 |
---|---|---|---|---|
2021-04-09 13:20:01 | 1617974401 | 2021-04-09 01:20:01 | 2021-04-09 13:20:01 | 2021-04-09 13:20:01 |