Specify timezone in ToDate(unix) in Pig

后端 未结 2 1179
无人共我
无人共我 2021-01-15 23:43

In my dataset I have dates in Unix timestamps. I want to convert these to a datetime in Apache Pig. For this I can use the ToDate() function as described here.

相关标签:
2条回答
  • 2021-01-16 00:24

    This is what you're looking for:

    ToDate(userstring, format, timezone)
    

    https://pig.apache.org/docs/r0.11.1/func.html#to-date

    Timezone stings: http://joda-time.sourceforge.net/timezones.html

    After Edwin's comment:

    In this specific case you can to do this:

    ToDate(ToString(ToDate((long) ts), 'yyyy-MM-dd hh:ss:mm'), 'yyyy-MM-dd hh:ss:mm', 'timezone')
    
    0 讨论(0)
  • 2021-01-16 00:44

    Just a side note, that Pig's ToDate uses offset-only timezones - how many hours + or - of GMT. Not the geographical ones. You can run into troubles with daylight saving times in this way. Consider computing time differences in hours since midnight: 2015-03-29 03:00:00+0200 minus 2015-03-29 00:00:00+0100 is 4 hours but 2015-03-29 03:00:00+0200 (Europe/Prague) minus 2015-03-29 00:00:00+0100 (Europe/Prague) is 3 hours.

    With Pig's ToDate, you can only achieve the former behavior.

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