[问题]hive时间戳不支持13位

  • hive是不支持13位的时间戳的,只支持10位的时间戳
    解决方式:
    1,除以1000后,转化为bigint
select from_unixtime(cast(1483675004884/1000 as bigint),"yyyy-MM-dd HH:mm:ss");

2,自己写个udf.

时间戳转化问题 vtime是string类型,值为 1483675004884,使用hive中的from_unixtime转化是一下情况,年份错误.

《[问题]hive时间戳不支持13位》 Paste_Image.png

udf样例如下:
create function sda_db.formatTimes as ‘com.sda.udf.FormatTimes’;
然后使用 formatTimes(vtime,’yyyy-MM-dd’) 就可以了.

public class FormatTimes extends UDF {
    public String evaluate(String s, String format) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
        long lt = new Long(s);
        Date date = new Date(lt);
        return simpleDateFormat.format(date);
    }
}
    原文作者:wangliang938
    原文地址: https://www.jianshu.com/p/5e962cec72d0
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞