hive 时间戳函数之unix_timestamp,from_unixtime
函数 时间 from hive unix timestamp
2023-09-11 14:19:34 时间
一. 日期>>>>时间戳
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
相关文章
- Go 函数编程
- Oracle计算时间函数(对时间的加减numtodsinterval、numtoyminterval) (转)
- (C++)浅谈多态基类析构函数声明为虚函数
- sqlserver 日期时间函数
- python中实现延时回调普通函数示例代码
- 使用python装饰器计算函数运行时间的实例
- Python built-in module time 内建时间库常用函数
- C++ 日期和时间的相关函数
- go匿名函数示例
- js日期格式化函数示例:将日期时间格式化成yyyy-mm-dd hh:ii:ss格式
- 使用noConclict后仍然能够在函数体内继续使用$的方法
- 简述数仓的时间域函数
- 设备和面向类的函数 基本的终端接口 termios termios 机构 取得前台进程组的 ID 设置前台进程组 ID 行控制函数 获得并设定状态 接口特性 波特率函数 基本的终端接口控制函数
- 习题 4.1 写两个函数,分别求两个整数的最大公约数和最小公倍数,用主函数调用两个函数,并输出结果,两个整数由键盘输入。
- 练习 3-4 在数的对二的补码表示中,我们编写的itoa函数不能处理最大的负数,即n等于-2字长-1的i情况。请解释其原因。修改该函数,使它在任何机器上运行时都能打印出正确的值。
- Python编程:time模块实现函数执行时间计时器
- 第5章 函数与函数式编程
- C++类的成员变量和成员函数
- Windows API一日一练(38)SetWindowPos函数
- mysql时间戳函数
- php函数 array_chunk
- MySQL 字符串与时间操作函数
- 函数__module_address()
- Mysql入门技能树-时间日期函数(二)
- 【跟学C++】C++类与对象—构造函数—析构函数(Study10)
- 完美解决在Windows下Vs Code编译不同C函数之间的调用问题