我正在尝试将时间戳列格式化为包含毫秒,但没有成功。我怎样才能将我的时间格式化为这样 - 2019-01-04 11:09:21.152?
我查看了文档并遵循了 SimpleDataTimeFormat ,pyspark 文档说该to_timestamp函数正在使用它。
这是我的数据框。
+--------------------------+
|updated_date |
+--------------------------+
|2019-01-04 11:09:21.152815|
+--------------------------+
Run Code Online (Sandbox Code Playgroud)
我使用毫秒格式没有成功,如下所示
>>> 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|
+--------------------------+-------------------+
Run Code Online (Sandbox Code Playgroud)
我希望updated_date_col2格式为2019-01-04 11:09:21.152