hive :
hive> select unix_timestamp('2018-11-07T17:24:09.313-05:00')
> ;
OK
_c0
NULL
Time taken: 1.061 seconds, Fetched: 1 row(s)
hive> select unix_timestamp('2018-11-07T17:24:09.313')
> ;
OK
_c0
NULL
Time taken: 0.078 seconds, Fetched: 1 row(s)
hive> select unix_timestamp('2018-11-07 17:24:09.313') ;
OK
_c0
1541636649
可以發現帶時區的時間,unix_timestamp無法轉換。
hive> select unix_timestamp('2018-11-07 17:24:09.313+01:00');
OK
_c0
1541636649
hive> select unix_timestamp('2018-11-07 17:24:09.313-05:00');
OK
_c0
1541636649
可以發現其也無法識別時區的變化
hive> select to_unix_timestamp('2018-11-07T17:24:09.313+01:00')
> ;
OK
_c0
NULL
Time taken: 0.089 seconds, Fetched: 1 row(s)
hive> select to_unix_timestamp('2018-11-07 17:24:09.313+01:00');
OK
_c0
1541636649
Time taken: 0.065 seconds, Fetched: 1 row(s)
hive> select to_unix_timestamp('2018-11-07T17:24:09.313');
OK
_c0
NULL
Time taken: 0.055 seconds, Fetched: 1 row(s)
hive> select to_unix_timestamp('2018-11-07 17:24:09.313');
OK
_c0
1541636649
to_unix_timestamp也是一樣的效果,都是廢物,沒法用於global team。
Spark:
spark-sql> select to_utc_timestamp(CAST('2018-11-22T14:12:09.530+01:00' AS TimeSTamp),'GMT-7');
2018-11-22 13:12:09.53
Time taken: 0.105 seconds, Fetched 1 row(s)
spark-sql> select to_utc_timestamp(CAST('2018-11-22T14:12:09.530+01:00' AS TimeSTamp),'GMT-8');
2018-11-22 14:12:09.53
Time taken: 0.141 seconds, Fetched 1 row(s)
spark-sql> select to_utc_timestamp(CAST('2018-11-22T14:12:09.530+01:00' AS TimeSTamp),'UTC-8');
2018-11-22 06:12:09.53
Time taken: 0.043 seconds, Fetched 1 row(s)
spark-sql> select to_utc_timestamp(CAST('2018-11-22T14:12:09.530+01:00' AS TimeSTamp),'UTC-7');
2018-11-22 06:12:09.53
Time taken: 0.062 seconds, Fetched 1 row(s)
直接cast後使用to_utc_timestamp