在 Pig 的 ToDate(unix) 中指定时区 [英] Specify timezone in ToDate(unix) in Pig
问题描述
在我的数据集中,我有 Unix 时间戳的日期.我想将这些转换为 Apache Pig 中的日期时间.为此,我可以使用 ToDate()
函数,如 此处.但是我知道我的 Unix 时间戳是 GMT/UTC,但是使用 ToDate()
进行转换将导致我的本地时区.从 Unix 时间戳转换时,我看不到如何在此函数中指定时区.我不想在转换后手动调整日期时间,因为这对夏令时来说是一个巨大的痛苦.希望有人有好的建议,我们将不胜感激.
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:mm:ss' )
结果是 (2014-11-28 04:04:32) 这是欧洲中部时间的时间,但我希望这是格林威治标准时间的 (2014-11-28 03:04:32).
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
埃德温发表评论后:
在这种特定情况下,您可以这样做:
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屋!