pyspark.sql.functions.current_timezone#

pyspark.sql.functions.current_timezone()[source]#

Returns the current session local timezone.

New in version 3.5.0.

Returns
Column

current session local timezone.

Examples

>>> spark.conf.set("spark.sql.session.timeZone", "America/Los_Angeles")
>>> from pyspark.sql import functions as sf
>>> spark.range(1).select(sf.current_timezone()).show()
+-------------------+
| current_timezone()|
+-------------------+
|America/Los_Angeles|
+-------------------+

Switch the timezone to Shanghai.

>>> spark.conf.set("spark.sql.session.timeZone", "Asia/Shanghai")
>>> spark.range(1).select(sf.current_timezone()).show()
+------------------+
|current_timezone()|
+------------------+
|     Asia/Shanghai|
+------------------+
>>> spark.conf.unset("spark.sql.session.timeZone")