from pyspark.sql.functions import from_utc_timestamp, current_timestamp
# Get the current timestamp in the local timezone.
current_timestamp_local = current_timestamp()
# Convert the current timestamp to UTC.
current_timestamp_utc = from_utc_timestamp(current_timestamp_local)
# Print the current UTC time.
print(current_timestamp_utc)
2条答案
按热度按时间ctehm74n1#
我可以提出一个非常简单的方法:从pyspark.sql.functions模块导入from_utc_timestamp()函数,调用current_timestamp()函数获取本地时区的当前时间戳,然后将当前时间戳传递给from_utc_timestamp()函数将其转换为UTC。
gblwokeq2#
你可以这样做。获取代码将运行的机器的时区,并使用它将
current_timestamp()
转换为UTC时间戳,如下所示。输出量: