Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spark parse string to timestamp with timezone

I have a string like:

2018-03-21T08:15:00+01:00

and wonder how to preserve the time zone / shift from UTC when parsing it in Spark.

Seq("2018-03-21T08:15:00+01:00").toDF.select('value, to_timestamp('value, "yyy-MM-ddTHH:mm:ss")).show(false)

unfortunately only yields null. Even my format string which is omitting the shift only returns null.

like image 531
Georg Heiler Avatar asked Mar 06 '23 12:03

Georg Heiler


1 Answers

T is not a format specifier so it should be escaped:

"yyyy-MM-dd'T'HH:mm:ss"

and timezone is denoted by X

"yyy-MM-dd'T'HH:mm:ssXXX"
like image 51
Alper t. Turker Avatar answered Mar 24 '23 18:03

Alper t. Turker