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.
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')
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.