title: How to convert the Zulu datetime to UTC with offset in pyspark and spark sql
body: <p>I have the below date time in string type. I want to convert that into UTC with offset</p>
  <pre><code>spark = SparkSession.builder.appName(&quot;Test&quot;).enableHiveSupport().getOrCreate()
      print(&quot;Print statement-1&quot;)
      schema = StructType([
          StructField(&quot;author&quot;, StringType(), False),       
          StructField(&quot;dt&quot;, StringType(), False)
      ])
  
      data = [
          [&quot;author1&quot;, &quot;2022-07-22T09:25:47.261Z&quot;],
          [&quot;author2&quot;, &quot;2022-07-22T09:26:47.291Z&quot;],
          [&quot;author3&quot;, &quot;2022-07-22T09:23:47.411Z&quot;],
          [&quot;author4&quot;, &quot;2022-07-224T09:25:47.291Z&quot;]
      ]
  
      df = spark.createDataFrame(data, schema)
  </code></pre>
  <p>I want to convert dt column as UTC with offset.</p>
  <p>For example the first row value as 2022-07-22T09:25:47.2610000 +00:00</p>
  <p>How to do that in pyspark and sparkSQL.</p>
  <p>I can easily do that using regex_replace</p>
  <pre><code>df=df.withColumn(&quot;UTC&quot;,regexp_replace('dt', 'Z', '000 +00:00'))
  </code></pre>
  <p>bcoz Z is same as +00:00. But I am not sure that regexp_replace is correct of doing the conversion. Is there any method which can do the correct conversion rather than regex_replace?</p>