在Pig中指定ToDate(unix)中的时区 [英] Specify timezone in ToDate(unix) in Pig
问题描述
在我的数据集中,我有日期在Unix时间戳。我想将它们转换为Apache Pig中的日期时间。为此,我可以使用 ToDate()
函数,如这里。但是,我知道我的Unix时间戳记是GMT / UTC,但是使用 ToDate()
转换将导致我的本地时区。当从Unix时间戳转换时,我看不到如何在此函数中指定时区。我不想在转换后手动调整datetime,因为这是夏令时的巨大痛苦。希望有人有一个很好的建议,每一个帮助将不胜感激。
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. However I know my Unix timestamps to be in GMT / UTC, but converting using ToDate()
will result in my local timezone. I don't see how I can specify the timezone in this function when converting from a Unix timestamp. I don't want to manually adjust the datetime after conversion, because this is a huge pain with daylight savings time. Hopefully someone has a good suggestion, every help will be appreciated.
这里有一个例子:
ToString( ToDate( (long)'1417145524000'), 'yyyy-MM-dd hh:ss:mm' )
结果(2014-11-28 04:04:32)这是CET的时间,但是我想要这样做(2014-11-28 03:04:32) GMT。
results in (2014-11-28 04:04:32) which is the time in CET, however I want this to be (2014-11-28 03:04:32) in GMT.
推荐答案
这是你要找的:
ToDate(userstring, format, timezone)
https://pig.apache.org/docs/r0.11.1/func。 html#to-date
时区戳:
http://joda-time.sourceforge.net/timezones.html
Edwin发表评论后:
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')
这篇关于在Pig中指定ToDate(unix)中的时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!