dcx-1993
一. 日期>>>>时间戳

1.unix_timestamp() 获取当前时间戳

例如:select unix_timestamp()   --1565858389

2.unix_timestamp(string timestame) 输入的时间戳格式必须为\'yyyy-MM-dd HH:mm:ss\',如不符合则返回null

例如:
select unix_timestamp(\'2019-08-15 16:40:00\')   --1565858400
select unix_timestamp(\'2019-08-15\')  --null

3.unix_timestamp(string date,string pattern) 将指定时间字符串格式字符串转化成unix时间戳,如不符合则返回null


例如:
select unix_timestamp(\'2019-08-15\',\'yyyy-MM-dd\')   --1565798400

select unix_timestamp(\'2019-08-15 16:40:00\',\'yyyy-MM-dd HH:mm:ss\')   --1565858400

select unix_timestamp(\'2019-08-15\',\'yyyy-MM-dd HH:mm:ss\')   --null

二. 时间戳>>>>日期

1.from_unixtime(bigint unixtime,string format) 将时间戳秒数转化为UTC时间,并用字符串表示,可通过format规定的时间格式,指定输出的时间格式,其中unixtime 是10位的时间戳值,而13位的所谓毫秒的是不可以的。

例如:
select from_unixtime(1565858389,\'yyyy-MM-dd HH:mm:ss\')  --2019-08-15 16:39:49

select from_unixtime(1565858389,\'yyyy-MM-dd\')   --2019-08-15

2.如果unixtime为13位的,需要先转成10位

select from_unixtime(cast(1553184000488/1000 as int),\'yyyy-MM-dd HH:mm:ss\')   --2019-03-22 00:00:00

select from_unixtime(cast(substr(1553184000488,1,10) as int),\'yyyy-MM-dd HH:mm:ss\')  --2019-03-22 00:00:00

 三.获取当前时间

select from_unixtime(unix_timestamp(),\'yyyy-MM-dd HH:mm:ss\')   -- 2019-08-15 17:18:55

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-03-04
  • 2021-11-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2021-11-04
  • 2022-12-23
相关资源
相似解决方案