HDFS Apache Spark如何将澳大利亚/墨尔本时间转换为UTC?

qjp7pelc  于 2022-12-09  发布在  HDFS
关注(0)|答案(1)|浏览(170)

如何在Scala的Apache Spark中将日期时间字符串(如澳大利亚/墨尔本时间21/10/2021 15:15:28)转换为UTC?

8ljdwjyq

8ljdwjyq1#

试试这个(当然你可以忽略数据的创建,我添加它是为了让你了解流:列的名称和类型):

Seq("21/10/2021 15:15:28").toDF("timeStr")
      .withColumn("australiaMelbourneTime", to_timestamp(col("timeStr"), "dd/MM/yyyy HH:mm:ss"))
      .withColumn("utcTime", to_utc_timestamp(col("australiaMelbourneTime"), "Australia/Melbourne"))

输出(测试):

+-------------------+----------------------+-------------------+
|            timeStr|australiaMelbourneTime|            utcTime|
+-------------------+----------------------+-------------------+
|21/10/2021 15:15:28|   2021-10-21 15:15:28|2021-10-21 04:15:28|
+-------------------+----------------------+-------------------+

相关问题