หมายเหตุ
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลอง ลงชื่อเข้าใช้หรือเปลี่ยนไดเรกทอรีได้
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลองเปลี่ยนไดเรกทอรีได้
Converts the timestamp without time zone sourceTs from the sourceTz time zone to targetTz.
For the corresponding Databricks SQL function, see convert_timezone function.
Syntax
from pyspark.databricks.sql import functions as dbf
dbf.convert_timezone(sourceTz=<sourceTz>, targetTz=<targetTz>, sourceTs=<sourceTs>)
Parameters
| Parameter | Type | Description |
|---|---|---|
sourceTz |
pyspark.sql.Column, optional |
The time zone for the input timestamp. If it is missed, the current session time zone is used as the source time zone. |
targetTz |
pyspark.sql.Column |
The time zone to which the input timestamp should be converted. |
sourceTs |
pyspark.sql.Column or str |
A timestamp without time zone. |
Returns
pyspark.sql.Column: A new column that contains a timestamp for converted time zone.
Examples
spark.conf.set("spark.sql.session.timeZone", "America/Los_Angeles")
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('2015-04-08 00:00:00',)], ['ts'])
df.select(
'*',
dbf.convert_timezone(None, dbf.lit('Asia/Hong_Kong'), 'ts')
).show()
df = spark.createDataFrame([('2015-04-08 15:00:00',)], ['ts'])
df.select(
'*',
dbf.convert_timezone(dbf.lit('Asia/Hong_Kong'), dbf.lit('America/Los_Angeles'), df.ts)
).show()
spark.conf.unset("spark.sql.session.timeZone")