pyspark.sql.functions.unix_timestamp(timestamp: Optional[ColumnOrName] = None, format: str = 'yyyy-MM-dd HH:mm:ss') → pyspark.sql.column.Column[source]

Convert time string with given pattern (‘yyyy-MM-dd HH:mm:ss’, by default) to Unix time stamp (in seconds), using the default timezone and the default locale, return null if fail.

if timestamp is None, then it returns current timestamp.

New in version 1.5.0.


>>> spark.conf.set("spark.sql.session.timeZone", "America/Los_Angeles")
>>> time_df = spark.createDataFrame([('2015-04-08',)], ['dt'])
>>>'dt', 'yyyy-MM-dd').alias('unix_time')).collect()
>>> spark.conf.unset("spark.sql.session.timeZone")