hive教程:格式化日期-将时间戳格式化,返回字符串类型

说明

将 时间戳 进行格式化,返回 string 类型

语法

select from_unixtime(unix_timestamp(),format)

参数解释:

  • unix_timestamp():时间戳
  • format:格式化参数
format参数有:
yyyy-MM-dd HH:mm:ss
yyyy-MM-dd
HH:mm:ss

例子

提示:查询当前时区时间戳

select unix_timestamp()

执行结果:1651881390

格式化例子

返回格式:年年年年-月月-日日 时时:分分:秒秒:

select from_unixtime(unix_timestamp(),"yyyy-MM-dd HH:mm:ss")

返回格式:年年年年-月月-日日:

select from_unixtime(unix_timestamp(),"yyyy-MM-dd")

返回格式:时时:分分:秒秒:

select from_unixtime(unix_timestamp(),"HH:mm:ss")

原文出处:/show_1IX3GZEIvQcj.html