- 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转化是一下情况,年份错误.
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);
}
}