hive时间戳函数之unix_timestamp(),from_unixtime,to_utc_timestamp
一. 日期>>>>时间戳
1.unix_timestamp() 获取当前时间戳
例如:
当前时间戳:
select unix_timestamp() --1565858389
获取当前时间:
echo `date -d 'now' '+%Y-%m-%d'` -- 2020-07-16
获取当前时间:
echo `date +%Y%m%d` --20200716
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') --1565798400select unix_timestamp('2019-08-15 16:40:00','yyyy-MM-dd HH:mm:ss') --1565858400select 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:49select 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:00select 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
to_utc_timestamp(current_timestamp,'GMT-8') -- 2019-08-15 17:18:55
四.当前时间上增减几天
date_add(current_date,-32) --获取当前时间前32天的时间
hive时间戳函数之unix_timestamp(),from_unixtime,to_utc_timestamp相关推荐
- hive 日期转时间戳函数之unix_timestamp,时间戳转日期函数之from_unixtime
一. 日期>>>>时间戳 默认返回的时间戳都是 10 位,如果是 13位,要特殊处理,看下面 1.unix_timestamp() 获取当前时间戳 例如:select un ...
- Hive常用函数大全
目录 第1章 算数运算 1.1 加法: + 1.2 减法: - 1.3 乘法: * 1.4 除法: / 1.5 取余: % 1.6 位与: & 1.7 位或: | 1.8 位异或: ^ 1.9 ...
- HIVE基础函数手册
一.关系运算 1. 等值比较: = 语法:A=B 操作类型:所有基本类型 描述:如果表达式A与表达式B相等,则为TRUE:否则为FALSE 举例: hive>select 1 from lxw_ ...
- hive时间函数入门
1)当前系统时间函数:current_date().current_timestamp().unix_timestamp() -- 函数1:current_date(); 当前系统日期 格式:&quo ...
- 【Hive】FROM_UNIXTIME() 和 UNIX_TIMESTAMP()时间戳函数用法
今天用 hive 进行 ETL时,需要对时间戳进行格式化, 其中还需要用到正则表达式及一些时间函数,在这里简单总结一下unix_timestamp.from_unixtime的用法,仅供参考. 先看下 ...
- unix_timestamp 时间戳函数用法(hive)
一.unix_timestamp函数用法 1.unix_timestamp() 得到当前时间戳 2.如果参数date满足yyyy-MM-dd HH:mm:ss形式,则可以直接unix_timest ...
- unix_timestamp、from_unixtime时间戳函数的使用
最近在做一个关于Spark sql清洗数据的项目,其中需要用到正则表达式及一些函数,在这里简单总结一下unix_timestamp.from_unixtime的用法,仅供参考. 一.unix_time ...
- mysql to unixtime_转 善用mysql中的FROM_UNIXTIME()函数和UNIX_TIMESTAMP()函数
我们经常会面临要从数据库里判断时间,取出特定日期的查询.但是数据库里储存的都是unix时间戳,处理起来并不是特别友好.幸而MYSQL提供了几个处理时间戳的函数,可以帮助我们在查询的时候,就将时间戳格式 ...
- Hive常用函数 -- 日期函数
UNIX时间戳转日期函数: from_unixtime 语法: from_unixtime(bigint unixtime[, string format]) 返回值: string 说明: 转化UN ...
最新文章
- python request-python-request-各方法使用及格式
- Tomcat - Tomcat 8.5.55 启动过程源码分析阶段一_init实例化Bootstrap
- 学习Git_12.10
- visual studio 2010 开发net 2.0 3.5项目
- 210129阶段三调试、进程间通信-共享内存
- java读取resouces目录下文件
- 中国料斗秤行业市场供需与战略研究报告
- 三星死守中国市场,强撑溢价难挽回颓势吗?
- swift3.0 coreData的使用-日记本demo
- 深度神经网络训练过程中为什么验证集上波动很大_一个值得深思的问题?为什么验证集的loss会小于训练集的loss...
- Unity与安卓开发的一些路径知识
- DSP技术在移动通信中的应用
- H3C交换机常用配置命令
- css+div透明参数设置
- 为什么要面向对象编程?
- 我的高中时代──纪念1995年进入高中20周年
- 计算机机房管理具体工作和职责,机房职责_机房岗位职责_机房工作职责
- 如何判断一个 js 变量是数组类型
- L. Lifeguards(排序)
- 小红伞杀毒软件自动化调用