presto集成kudu获取当前时间及时间转换

1.获取当前时间年月日时分秒(yyyy-MM-dd HH:mm:ss)

select substr(cast(now() as varchar),1,19) as nowTime;

在这里插入图片描述

2.时间戳转标准日期

select
'1566748800000' as "毫秒时间戳",
substr('1566748800000',1,10) as "秒时间戳",
current_date as "当前时间年月日",
format_datetime(from_unixtime(cast(substr('1566748800000',1,10) as int)),'yyyy-MM-dd') as "年月日",
format_datetime(from_unixtime(cast(substr('1566748800000',1,10) as int)),'yyyy-MM-dd HH:mm:ss') as "年月日时分秒",
from_unixtime(cast(substr('1566748800000',1,10) as int)) as "年月日时分秒毫秒"; -- 将13位毫秒级的unix timestamp截取到秒级别

在这里插入图片描述

附录:日期和时间功能

current_date -> date
返回截至查询开始的当前日期。

current_time -> time with time zone
返回截至查询开始的当前时间。

current_timestamp -> timestamp with time zone
返回截至查询开始的当前时间戳。

current_timezone() →varchar
以IANA定义的格式(例如America/Los_Angeles)或相对于UTC的固定偏移量返回当前时区(例如+08:35)

date(x ) →日期
这是的别名。CAST(x AS date)

from_iso8601_timestamp(字符串) →带有时区的时间戳
解析格式化string为的ISO 8601 。timestamp with time zone

from_iso8601_date(字符串) →日期
解析格式化string为的ISO 8601 date。

from_unixtime(unixtime ) →时间戳
返回UNIX时间戳记unixtime作为时间戳记。

from_unixtime(unixtime,string ) →带时区的时间戳
返回UNIX时间戳unixtime作为带有时区的时间戳(string用于时区)。

from_unixtime(unixtime,hours,minutes ) →带时区的时间戳
将UNIX时间戳unixtime作为带有时区的时间戳返回,hours并使用和minutes作为时区偏移量。

localtime -> time
返回截至查询开始的当前时间。

localtimestamp -> timestamp
返回截至查询开始的当前时间戳。

now() →带时区的时间戳
这是的别名current_timestamp。

to_iso8601(x ) →varchar
格式化x为ISO 8601字符串。x可以是日期,时间戳或带时区的时间戳。

to_milliseconds(间隔) →bigint
interval以毫秒为单位返回秒。

to_unixtime(时间戳记) →两倍
timestamp作为UNIX时间戳返回。

附录参考链接

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值