pyspark.sql.functions.timestamp_millis

pyspark.sql.functions.timestamp_millis(col: ColumnOrName) → pyspark.sql.column.Column[source]

Creates timestamp from the number of milliseconds since UTC epoch.

New in version 3.5.0.

Parameters
colColumn or str

unix time values.

Returns
Column

converted timestamp value.

Examples

>>> spark.conf.set("spark.sql.session.timeZone", "UTC")
>>> time_df = spark.createDataFrame([(1230219000,)], ['unix_time'])
>>> time_df.select(timestamp_millis(time_df.unix_time).alias('ts')).show()
+-------------------+
|                 ts|
+-------------------+
|1970-01-15 05:43:39|
+-------------------+
>>> time_df.select(timestamp_millis('unix_time').alias('ts')).printSchema()
root
 |-- ts: timestamp (nullable = true)
>>> spark.conf.unset("spark.sql.session.timeZone")