pyspark.sql.functions.convert_timezone¶
-
pyspark.sql.functions.
convert_timezone
(sourceTz: Optional[pyspark.sql.column.Column], targetTz: pyspark.sql.column.Column, sourceTs: ColumnOrName) → pyspark.sql.column.Column[source]¶ Converts the timestamp without time zone sourceTs from the sourceTz time zone to targetTz.
New in version 3.5.0.
- Parameters
- Returns
Column
timestamp for converted time zone.
Examples
>>> df = spark.createDataFrame([('2015-04-08',)], ['dt']) >>> df.select(convert_timezone( ... None, lit('Asia/Hong_Kong'), 'dt').alias('ts') ... ).show() +-------------------+ | ts| +-------------------+ |2015-04-08 00:00:00| +-------------------+ >>> df.select(convert_timezone( ... lit('America/Los_Angeles'), lit('Asia/Hong_Kong'), 'dt').alias('ts') ... ).show() +-------------------+ | ts| +-------------------+ |2015-04-08 15:00:00| +-------------------+