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.获取当前时间年月日时分秒(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 "秒时间戳",format_datetime(from_unixtime(cast(substr('1566748800000',1,10) as int)),'yyy