yyyy-MM-dd与yyyyMMdd000000转换的三种方法

方法一:date_format(只支持yyyy-MM-dd -> yyyyMMdd000000)

select date_format('2019-10-07', 'yyyyMMdd000000')
--

方法二:from_unixtime + unix_timestamp

select from_unixtime(unix_timestamp('2019-10-07', 'yyyy-MM-dd'), 'yyyyMMdd000000')
-- select from_unixtime(unix_timestamp(substr('',1,8),'yyyyMMdd'),'yyyy-MM-dd')
-- 2019-10-07

方法三:substr + concat

select concat(substr('2019-10-07',1,4),substr('2019-10-07',6,2),substr('2019-10-07',9,2),'')
-- select concat(substr('',1,4),'-',substr('',5,2),'-',substr('',7,2))
-- 2019-10-07

时间转换方法详解

unix_timestamp:格式化日期转时间戳

select unix_timestamp('2019-10-07 13:24:20','yyyy-MM-dd HH:mm:ss')
-- select unix_timestamp('','yyyyMMdd')
--

from_unixtime:时间戳转格式化日期

select from_unixtime(1570425860,'yyyy-MM-dd HH:mm:ss')
-- 2019-10-07 13:24:20 select from_unixtime(1570425860,'yyyyMMdd000000')
--

date_format:yyyy-MM-dd HH:mm:ss 时间转格式化时间

select date_format('2019-10-07 13:24:20', 'yyyyMMdd000000')
-- select date_format('2019-10-07', 'yyyyMMdd000000')
--

yyyy-MM-dd HH:mm:ss 注意

MM为月份

mm为分钟

HH为24小时制

hh为12小时制

【HIVE】各种时间格式处理的更多相关文章

  1. python获取hive表时间格式最大分区

    #获取表的最大分区 import boto3 from datetime import datetime,timedelta def get_max_partition(db_name,table_n ...

  2. hive笔记:时间格式的统一

    一.string类型,年月日部分包含的时间统一格式: 原数据格式(时间字段为string类型) 取数时间和格式的语法  2018-11-01 00:12:49.0 substr(regexp_repl ...

  3. Hive presto和hive时间格式转换

    1.北京时间格式   to   unix时间格式 数据格式: 2017-11-17 08:28:13 2017-11-17 08:28:10 2017-11-17 08:27:51.343 2017- ...

  4. hive中时间操作(一)

    转:https://blog.csdn.net/u012474716/article/details/78925319/ hive中常用的时间为时间戳和日期格式之间的转换 常用的函数为: to_dat ...

  5. sql的时间格式

    sql中的时间格式转换主要有:date_format函数,str_to_date函数 1. 首先选择一个数据库 use db_name; 2. 显示当前时区的时间: SELECT NOW(); 3. ...

  6. NSDateFormatter 时间格式转换

    NSString *strDate = @“Wed Apr ::”; NSDateFormatter *dateFomatter =[[NSDateFormatter alloc] init]; [d ...

  7. 时间格式转换—将后台返回的/Date(1448954018000)/格式转换为正常的时间格式

    用JS实现方法: function ChangeDateFormat(cellval) { )); < ? ) : date.getMonth() + ; ? " + date.get ...

  8. Newtonsoft.Json 序列化和反序列化 时间格式【转】

    1.JSON序列化 string JsonStr= JsonConvert.SerializeObject(Entity); eg:   A a=new A(); a.Name="Elain ...

  9. Spring mvc时间格式处理

    spring mvc中,如果时间格式是yyyy-MM-dd,传入后台会报错,要增加一些配置才可以. 1.修改spring-mvc.xml,增加org.springframework.format.su ...

  10. db2 日期时间格式

    db2日期和时间常用汇总 1.db2可以通过SYSIBM.SYSDUMMY1.SYSIBM.DUAL获取寄存器中的值,也可以通过VALUES关键字获取寄存器中的值. SELECT 'HELLO DB2 ...

随机推荐

  1. ObjectMapper2

    ObjectMapper mapper = new ObjectMapper();                try {                    user = mapper.read ...

  2. C 扩展对闭包特性的支持

    今日听说某君批评 C 语言说它[输入一个参数返回一个函数]很困难. 例如在 Python 中,你可以 def addn(n): def addx(x): return n + x return add ...

  3. office web apps server安装

    1.准备服务器 准备一台windows server 2012 R2服务器,修改计算机名称加入域,如果是通过虚拟机复制导致sid冲突,可以先运行 c:\windows\system32\sysprep ...

  4. codeforces Educational Codeforces Round 24 (A~F)

    题目链接:http://codeforces.com/contest/818 A. Diplomas and Certificates 题解:水题 #include <iostream> ...

  5. Unity3D 客户端编程

    Photon Server 和 Unity3D 数据交互: Photon Server 服务端编程 Unity3D 客户端编程. VS2017 之 MYSQL实体数据模 1:打开unity新建新项目, ...

  6. Spring boot 自定义 Resolver 支持 interface 类型参数

    在编写 RestController 层的代码时,由于数据实体类定义了接口及实现类,本着面向接口编程的原则,我使用了接口作为 RestController 方法的入参. 代码大致如下(省略具体业务部分 ...

  7. csapp:第八章 异常控制流ECF

    第八章 异常控制流ECF 8.1 异常 Exception graph LR E[异常Exception]-->E2[中断:异步异常] E-->E3[同步异常] E3-->陷阱 E3 ...

  8. Numpy版本问题,import tensorflow as tf 报警:“ FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'”

    tensorflow成功安装后 import tensorflow as tf 报警:“ FutureWarning: Passing (type, 1) or '1type' as a synony ...

  9. Python入门基础:七段数码管绘制

    1.在学习Python的过程中,运用所学的一些基础知识,进行一些简单的编程,可以收获很多乐趣.在生活中,LED灯无处不在,荧幕显示的广告词,给我们呈现出动态的视觉效果.下面,则以最简单的显示日期为例, ...

  10. Django之使用内置函数和celery发邮件

    邮箱配置 开启stmp服务 以163邮箱为例,点击设置里面的stmp 开启客户端授权密码 如上所示,因为我已经开启了,所以出现的是以上页面. 这样,邮箱的准备就已经完成了. 使用Django内置函数发 ...