pyspark.sql.functions.from_utc_timestamp()中的tz参数

时间:2016-03-29 02:30:52

标签: apache-spark timezone pyspark pyspark-sql

您好我目前正在通过Spark处理时间序列数据并处理时区。

SparkSQL的一些内置函数使用了特定的时区参数,例如:

pyspark.sql.functions.from_utc_timestamp(timestamp, tz)

Assumes given timestamp is UTC and converts to given timezone.

>>> df = sqlContext.createDataFrame([('1997-02-28 10:30:00',)], ['t'])
>>> df.select(from_utc_timestamp(df.t, "PST").alias('t')).collect()
[Row(t=datetime.datetime(1997, 2, 28, 2, 30))]
New in version 1.5.

在我的情况下,使用时区短手可能不方便,因为时区信息以" +01:00"的格式存储。

所以我的问题是:如何将偏移字符串合并为" +01:00"进入火花数据框,以便考虑偏移量?

1 个答案:

答案 0 :(得分:0)

您可以使用 GMT + 01:00 ,如中所述 java.util.TimeZone doc