我有以下数据框:
+----------+-------------------+
| timestamp| created|
+----------+-------------------+
|1519858893|2018-03-01 00:01:33|
|1519858950|2018-03-01 00:02:30|
|1519859900|2018-03-01 00:18:20|
|1519859900|2018-03-01 00:18:20|
如何正确创建时间戳`?
我能够创建timestamp
列,它是纪元时间戳,但日期不一致:
df.withColumn("timestamp",unix_timestamp($"created"))
例如,1519858893
指向2018-02-28
。
最佳答案
只需使用date_format
和to_utc_timestamp
内置函数
import org.apache.spark.sql.functions._
df.withColumn("timestamp", to_utc_timestamp(date_format(col("created"), "yyy-MM-dd"), "Asia/Kathmandu"))
关于scala - 如何更改 Spark 中的日期格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49321166/