Impala时间转换to_date、to_timestamp
在时间的运算上,也常常使用到日期格式的转换,如日期字符串转为日期型,日期转为格式化字符串,是两种常见的需求;另外也有需要将时间转为时间戳的场景等等;
时间数据的转换上,主要用to_date、to_timestamp,即可满足日期字符串转为日期型的需求;
from_timestamp、from_unixtime,即可满足日期转为格式化字符串的需求;
unix_timestamp,可以满足具有时间戳要求的场景;
再有其他场景大家可以根据需要,看看下面的方法有没有你所需要的哈
方法说明:
序号 |
语法类型/方法名称 |
输出类型 |
使用说明 |
1 |
to_date(timestamp date) |
string |
返回时间戳对应的date |
2 |
to_timestamp(bigint unixtime) |
timestamp |
返回整数对应的timestamp值 |
3 |
to_timestamp(string date,string pattern) |
timestamp |
返回字符串对应的timestamp值 |
4 |
to_utc_timestamp(timestamp t,string timezone) |
timestamp |
指定时区的时间戳转化为UTC时区的时间戳 |
5 |
from_timestamp(timestamp t,string pattern) |
string |
把timestamp按照pattern进行格式化 |
6 |
from_timestamp(string date,string pattern) |
string |
把date按照pattern进行格式化 |
7 |
from_unixtime(bigint unixtime) |
string |
把时间戳秒数转化为本地地区中的字符串 |
8 |
from_unixtime(bigint unixtime,string pattern) |
string |
时间戳转化为本地时区字符串,pattern格式 |
9 |
from_utc_timestamp(timestamp t,string timezone) |
timestamp |
UTC时区指定时间戳转化为指定时区时间戳 |
10 |
unix_timestamp(string datetime) |
bigint |
把string类型的date或日期转化成时间戳Unix |
11 |
unix_timestamp(timestamp datetime) |
bigint |
把string类型的timestamp转化成时间戳Unix |
12 |
unix_timestamp(string datetime,string pattern) |
bigint |
日期按pattern转化成时间戳Unix |
方法示例:
序号 |
语法类型/方法名称 |
输出结果 |
1 |
select now() | 2022-11-10 14:22:36.927 |
2 |
select to_date(now()) | 2022-11-10 |
3 |
select to_timestamp(1668089883) | 2022-11-10 14:18:03.000 |
4 |
select to_timestamp('2022/11/10','yyyy/MM/dd') | 2022-11-10 00:00:00.000 |
5 |
select to_utc_timestamp(now(),'Asia/Shanghai') | 2022-11-10 06:23:36.036 |
6 |
select from_timestamp(now(),'yyyy/MM') | 2022/11 |
7 |
select from_timestamp('2022-11-10','yyyy/MM') | 2022/11 |
8 |
select from_unixtime(1668089883) | 2022-11-10 14:18:03 |
9 |
select from_unixtime(1668089883,'yyyy/MM') | 2022/11 |
10 |
select from_utc_timestamp(now(),'Asia/Shanghai') | 2022-11-10 22:24:25.055 |
11 |
select unix_timestamp('2022-11-01') | 1667260800 |
12 |
select unix_timestamp(now()) | 1668090279 |
13 | select unix_timestamp('2022-11-01 14:26:27','yyyy-MM-dd HH:mm:ss') | 1667312787 |
Impala时间转换to_date、to_timestamp相关推荐
- impala 时间日期函数全解
参考文章: impala 时间日期函数全解 impala 下的SQL时间函数 --=========================================================== ...
- Oracle日期格式转换 to_date,to_char,to_timetamp 相互转换
Oracle日期格式转换 to_date,to_char,to_timetamp 相互转换 一.概述 1.本文主要记录Oracle数据库中,常见的日期格式转换.使用 to_char函数,将日期转换为字 ...
- 字符串和时间转换sql
oracle: 当前时间:sysdate – dual (Oracle中的一张内部表,只有一行一列,一般用作特定查询) 时间转字符串: to_char(date,format) select to_c ...
- postgres的时间转换
天下苦postgres时间转换久已! 最近在操作数据库时,遇到频繁的时间操作,每次弄完了就忘了,今天痛定思痛,下定决心(终于自己也受不了自己的lazy了)对postgres的时间操作进行一下总结.本文 ...
- GreenPlum 时间转换函数
从date.timestamp.time.interval类型中抽取子域值 方法一:extract extract函数从日期.时间数值里抽取子域,例如年.小时等. 格式: extract(field ...
- mysql 格林时间转换_格林时间转换成正常时间
uscdbmt@rac1:~> date +%s 1414741902 oracle中怎么把这个1414741902转换成正常时间格式 select Numtodsinterval(141474 ...
- 时间转换数字与日期互转
时间转换 再和java项目对接的时候,我们经常会遇到将数字类型与时间格式互相转化 数字转日期 FUNCTION number_to_date(p_number IN NUMBER) RETURN DA ...
- 格林时间转换成正常时间
uscdbmt@rac1:~> date +%s 1414741902 oracle中怎么把这个1414741902转换成正常时间格式 select Numtodsinterval(141474 ...
- HIVE 的时间转换函数
HIVE 的时间转换函数. 1,select unix_timestamp() 可以得到当前时间的时间戳. select unix_timestamp(时间格式) 可以得到当前时间的时间戳.两个时间戳 ...
最新文章
- “2021ISIG中国产业智能大会低代码峰会”即将开幕,钉钉宜搭叶周全受邀出席
- 注入点批量收集工具_原来微信群也是能够批量管理的,学到了
- #宝塔面板# #nginx+apache# KVS服务器运行环境搭建过程记录
- Spring_使用(JDBC)
- spring cloud构建互联网分布式微服务云平台-高可用的服务注册中心
- 芯烨打印机WEB API 调用HEX的模式DEMO
- 瓜子2019笔试java_2019秋招瓜子携程笔试题解(含题目) 点赞有offer
- 人脸识别最全综述:详解人脸识别技术、人才、趋势
- 智遥工作流中调用SAP基础数据
- Docker问题:ERROR: Pool overlaps with other one on this address space
- ESP8266 NodeMCU驱动OLED屏(SSD1306,4PIN,IIC)
- 解析 embedded.mobileprovision 获取信息
- XILINX DMA/Bridge Subsystem for PCI Express (XDMA)笔记1(基于VU250 board)
- ZJOI2018游记Round2
- svn怎么执行清理命令_C盘又见红了?一个C盘清理强迫症教你真正有效的解决方法!...
- 女赛--Girl Love Value (01背包)
- group by和order by的用法和区别
- 视频网站主机服务器,视频网站主机服务器
- Tkinter Cursors
- c语言 --- 指针