I want to convert an epoc field into a UTC timestamp and I am using the code below.
df.withColumn(
TargetColumn,
to_timestamp(from_unixtime(col(SourceColumn) / 1000), "yyyy-MM-dd HH:mm:ss")
A sample value for the SourceColumn is 1580452395095L which should yield 2020-01-31 06:33:15.0
however when I try this code it gives 2020-01-31 07:33:15.0
Seems like to_timestamp function uses the local timezone of the system, I even tried to set spark timezone as
spark.conf.set("spark.sql.session.timeZone", "UTC")
But this also didn't work, is there a way to make this code always convert to a UTC timestamp regardless of the environment it runs on?