I have a table which has a datetime in string type. I want to convert it into UTC timestamp. My local time zone is CDT. I first convert datetime into timestamp.
table = table.withColumn('datetime_dt', unix_timestamp(col('datetime'), "yyyy-MM-dd HH:mm:ss").cast("timestamp"))
Then, I try to convert this timestamp column into UTC time.
table = table.withColumn('datetime_UTC', to_utc_timestamp(table.datetime_dt, 'CDT'))
I also try this
table = table.withColumn('datetime_UTC', to_utc_timestamp(col('datetime_dt'), 'CDT'))
But it returns the same results. Here are some examples.
------------------------------------------------------------------
| datetime | datetime_dt | datetime_UTC |
------------------------------------------------------------------
|2019-01-01 00:49:00 | 2019-01-01 00:49:00 | 2019-01-01 00:49:00 |
------------------------------------------------------------------
|2019-01-01 02:06:00 | 2019-01-01 02:06:00 | 2019-01-01 02:06:00 |
------------------------------------------------------------------
|2019-01-02 05:15:00 | 2019-01-02 05:15:00 | 2019-01-02 05:15:00 |
------------------------------------------------------------------
Why does it give the same time without any conversion? I import to_utc_timestamp from pyspark.sql.functions.