我需要美国东部夏令时的当前时间戳,但current_timestamp()
返回太平洋标准时间.
已try 以下代码,但它不起作用,并在美国东部时间前6小时显示:
# Import the current_timestamp function
from pyspark.sql.functions import from_utc_timestamp
# Set the timezone to EST
spark.conf.set("spark.sql.session.timeZone", "EST")
# Get the current timestamp in EST
current_timestamp_est = spark.sql("SELECT from_utc_timestamp(current_timestamp(), 'EST') as current_timestamp_est")
# Show the current timestamp in EST
current_timestamp_est.show(truncate = False)
我还try 了下面的代码.但时间即将到来,就像2024-03-11 23:16:04.589275-04:00
岁.为什么它会和-4:00
一起出现?有没有办法摆脱-4:00
?
from datetime import datetime
from pytz import timezone
est = timezone('US/Eastern')
now_est = datetime.now(est)
#now_est1 = now_est[:26]
print(now_est)
有没有其他方法可以在变量中获取EST中的当前时间戳?