4

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.

zero323
  • 322,348
  • 103
  • 959
  • 935
Georg Heiler
  • 16,916
  • 36
  • 162
  • 292

1 Answers1

8

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"
Alper t. Turker
  • 34,230
  • 9
  • 83
  • 115