合并列 Scala 后得到错误的时间戳

Getting the wrong timestamp after combining columns Scala

所以我设法将年、月和日列合并为 1,然后将其与时间列合并。当我尝试将其转换为时间戳时,我弄错了。这是我试过的代码。

val df2 = df.withColumn("full_date", concat_ws("/", $"Month", $"Day", $"Year"))
// // df2.show()
val df3 = df2.withColumn("date_time", concat_ws(" ", $"full_date", $"TimeCST"))
// // df3.show()

val stamp = df3.withColumn("timestamp", unix_timestamp($"date_time", "M/d/yyyy h:mm a"))
stamp.show()

我得到的是 94668798,但它应该是 946752780。我尝试转换的示例日期是:1/1/2000 12:53 AM

来自 unix_timestamp 的文档:

Converts time string in format yyyy-MM-dd HH:mm:ss to Unix timestamp (in seconds), using the default timezone and the default locale.

换句话说,由于您的时间戳格式不包括时区,因此 Spark 将时间视为机器上配置的时区 运行 Spark。如果您想要不同时区的值,请先将 spark.sql.session.timeZone 设置为正确的名称:

spark.conf.set("spark.sql.session.timeZone", "Europe/Berlin")