How to convert a Date String from UTC to Specific TimeZone in HIVE?

前端 未结 2 799
陌清茗
陌清茗 2020-12-19 07:05

My Hive table has a date column with UTC date strings. I want to get all rows for a specific EST date.

I am trying to do something like the below:

Se         


        
相关标签:
2条回答
  • 2020-12-19 07:48

    This converts to CST with the daylight savings hour shift:

    to_date(FROM_UTC_TIMESTAMP(UNIX_TIMESTAMP(eff_timestamp, "yyyy-MM-dd'T'hh:mm:ss.SSS'Z'") * 1000, 'CST6CDT')) 
    
    0 讨论(0)
  • 2020-12-19 08:05

    Your system timezone CST doesn't matter for converting UTC to EST in Hive. You should be able to get the correct results with:

    TO_DATE(FROM_UTC_TIMESTAMP(UNIX_TIMESTAMP(T.date, "yyyy-MM-dd'T'hh:mm:ss.SSS'Z'") * 1000, 'EST'))
    

    Note that because UNIX_TIMESTAMP returns seconds, you will lose the millisecond component of your timestamp.

    0 讨论(0)
提交回复
热议问题