pyspark.sql.functions.timestamp_micros#

pyspark.sql.functions.timestamp_micros(col)[source]#

Creates timestamp from the number of microseconds 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_micros(time_df.unix_time).alias('ts')).show()
+--------------------+
|                  ts|
+--------------------+
|1970-01-01 00:20:...|
+--------------------+
>>> time_df.select(timestamp_micros('unix_time').alias('ts')).printSchema()
root
 |-- ts: timestamp (nullable = true)
>>> spark.conf.unset("spark.sql.session.timeZone")