Spark: converting GMT time stamps to Eastern taking daylight savings into account

Bob Swain

I'm trying to convert a column of GMT timestamp strings into a column of timestamps in Eastern timezone. I want to take daylight savings into account.

My column of timestamp strings look like this:

'2017-02-01T10:15:21+00:00'

I figured out how to convert the string column into a timestamp in EST:

from pyspark.sql import functions as F

df2 = df1.withColumn('datetimeGMT', df1.myTimeColumnInGMT.cast('timestamp'))
df3 = df2.withColumn('datetimeEST', F.from_utc_timestamp(df2.datetimeGMT, "EST"))

But the times don't change with daylight savings. Is there another function or something that accounts for daylight savings with converting the timestamps?

EDIT: I think I figured it out. In the from_utc_timestamp call above, I needed to use "America/New_York" instead of "EST":

df3 = df2.withColumn('datetimeET', F.from_utc_timestamp(df2.datetimeGMT, "America/New_York"))
Bob Swain

I ended up figuring out the answer, so I figured I would add it here. I also think that this question/answer is worthwhile because while I was searching for this issue before posting the question, I couldn't find anything about daylight savings for spark. I probably should have realized that I should search for the underlying java functions.

The answer to the question ended up being to use the string "America/New_York" instead of "EST". This correctly applies daylight savings.

from pyspark.sql import functions as F
df3 = df2.withColumn('datetimeET', F.from_utc_timestamp(df2.datetimeGMT, "America/New_York"))

EDIT:

This link shows a list of available time zone strings that can be used in this way: https://garygregory.wordpress.com/2013/06/18/what-are-the-java-timezone-ids/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Convert EST timestamp to GMT taking into account Daylight Savings

Date to UTC not taking into account daylight savings

Convert UTC Time to UTC+2 (Rome) taking into account DST (Daylight Savings)

Get number of milliseconds for a localised date, taking into account daylight savings

logfiles and daylight savings time

Python daylight savings time

Daylight savings time in java

Rails/Postgres query all records created after 5 PM in taking into account daylight savings switch?

Converting UTC date time to a time in the future, considering daylight savings time of a time zone

python time module: daylight savings

Moment handling daylight savings time

How to get real time zone offset taking into account daylight saving?

Taking care of daylight saving time when converting timezone

Converting to a non-daylight savings timezone

Python pytz, zoneinfo and daylight savings time

python: UTC to local daylight savings time

How to find the date and time daylight savings begins

Daylight savings time in Angular/Javascript Date

Handling date/time in java/android and daylight savings

Determining whether a timezone supports Daylight Savings Time

Laravel - Carbon Not Factoring in Daylight Savings Time

UIDatePicker does not respect Daylight Savings Time

Joda-time daylight savings in Jordan

Java8 and Daylight Savings Time

SAS daylight savings time conversion SAS

Converting time-stamps in the dataframe

Why doesn't DateTime.ToLocalTime() take into account daylight savings?

Easiest way to convert UTC to New Zealand date (account for daylight savings)?

How to convert UTC to Australian Eastern Daylight Time (AEDT)?