我有一个具有纪元时间的列的DF。纪元时间列的变量类型是字符串。我希望将其转换为时间戳。我正在使用以下命令
from pyspark.sql.functions import from_utc_timestamp
df = df.withColumn('start_time',from_unixtime(df.recognition_start_time,'UTC'))
df.select('recognition_start_time').show(10,False)
但是命令给了我空值。我正在犯什么错误?
Epoch Time : 1583471040000
Output expected :2020-03-06 05:04:00
在这里,from_unixtime
我们需要指定预期的输出格式(yyyy-MM-dd hh:mm:ss
),并通过使用from_utc_timestamp
可以将utc的输出转换为给定的时区。
Example:
spark.sql("""select from_utc_timestamp(from_unixtime("1583471040000"/1000,"yyyy-MM-dd hh:mm:ss"),"America/Chicago")""").show(false)
+---------------------+
|_c0 |
+---------------------+
|2020-03-05 05:04:00.0|
+---------------------+
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句