Date 什么';s unix_timestamp函数的逻辑在配置单元中将2位数格式的年份转换为4位数格式的年份?

Date 什么';s unix_timestamp函数的逻辑在配置单元中将2位数格式的年份转换为4位数格式的年份?,date,hadoop,hive,Date,Hadoop,Hive,例如,下面的配置单元脚本 select from_unixtime(unix_timestamp('30-Apr-50', 'dd-MMM-yy'), 'yyyy-MM-dd') as date1, from_unixtime(unix_timestamp('30-Apr-45', 'dd-MMM-yy'), 'yyyy-MM-dd') as date2, from_unixtime(unix_timestamp('30-Apr-35', 'dd-MMM-yy'), 'yyyy-MM-dd')

例如,下面的配置单元脚本

select 
from_unixtime(unix_timestamp('30-Apr-50', 'dd-MMM-yy'), 'yyyy-MM-dd') as date1,
from_unixtime(unix_timestamp('30-Apr-45', 'dd-MMM-yy'), 'yyyy-MM-dd') as date2,
from_unixtime(unix_timestamp('30-Apr-35', 'dd-MMM-yy'), 'yyyy-MM-dd') as date3;
结果如下

date1       date2       date3
1950-04-30  1945-04-30  2035-04-30
unix_timestamp函数将2位数的年份转换为4位数的年份,其背后的逻辑是什么?2位数年份转换为20**时是否有固定阈值?如果有,门槛是多少?是否有一种参数(“世纪中断”作为实际情况)可以根据某些条件设置世纪

年份:…
用于使用缩写年模式(“y”或 “yy”),SimpleDateFormat必须解释缩写的相对年份 到某个世纪。
它通过将日期调整为创建SimpleDataFormat实例之前的80年和之后的20年来实现此目的。
例如,使用“MM/dd/yy”模式和1997年1月1日创建的SimpleDataFormat实例,字符串“01/11/12”将解释为2012年1月11日,而字符串“05/04/64”将解释为1964年5月4日



代码遍历


谢谢,这完全消除了我的疑虑。对于unix_时间戳函数,是否有方法更改“80年前和20年后”时间窗口?例如,更改为“50年前和50年后”,不客气。截止日期似乎无法更改。
hive> select current_date;
2017-03-28

-- 20 years after today

hive> select from_unixtime(unix_timestamp('37-03-28','yy-MM-dd'));
2037-03-28 00:00:00

hive> select from_unixtime(unix_timestamp('37-03-29','yy-MM-dd'));
1937-03-29 00:00:00

-- 80 years before today

hive> select from_unixtime(unix_timestamp('37-03-29','yy-MM-dd'));
1937-03-29 00:00:00

hive> select from_unixtime(unix_timestamp('37-03-28','yy-MM-dd'));
2037-03-28 00:00:00
public class GenericUDFUnixTimeStamp extends GenericUDFToUnixTimeStamp {
...

public Object evaluate(DeferredObject[] arguments) throws HiveException {
    return (arguments.length == 0) ? currentTimestamp : super.evaluate(arguments);
  }
import java.text.SimpleDateFormat;
...

public class GenericUDFToUnixTimeStamp extends GenericUDF {
...
  private transient final SimpleDateFormat formatter = new SimpleDateFormat(lasPattern);
...
  public Object evaluate(DeferredObject[] arguments) throws HiveException {
...
        retValue.set(formatter.parse(textVal).getTime() / 1000);
...
  }
}