【发布时间】:2019-01-04 18:06:58
【问题描述】:
我正在尝试格式化我的时间戳列以包含毫秒但没有成功。如何格式化我的时间看起来像这样 - 2019-01-04 11:09:21.152 ?
我查看了文档并遵循了 SimpleDataTimeFormat ,pyspark 文档说 to_timestamp 函数正在使用它。
这是我的数据框。
+--------------------------+
|updated_date |
+--------------------------+
|2019-01-04 11:09:21.152815|
+--------------------------+
我使用毫秒格式没有任何成功,如下所示
>>> df.select('updated_date').withColumn("updated_date_col2",
to_timestamp("updated_date", "YYYY-MM-dd HH:mm:ss:SSS")).show(1,False)
+--------------------------+-------------------+
|updated_date |updated_date_col2 |
+--------------------------+-------------------+
|2019-01-04 11:09:21.152815|2019-01-04 11:09:21|
+--------------------------+-------------------+
我希望updated_date_col2 被格式化为2019-01-04 11:09:21.152
【问题讨论】:
-
时间戳类型没有毫秒。如果需要,您必须将列保留为字符串。
标签: apache-spark pyspark