如何在Python中将UTC转换为太平洋时区
我尝试了这个,但它无法正常工作
from datetime import datetime
from pytz import timezone
fmt = "%Y-%m-%d %H:%M:%S %Z%z"
# Current time in UTC
now_utc = 1348283733848
# Convert to US/Pacific time zone
now_pacific = now_utc.astimezone(timezone('US/Pacific'))
print now_pacific.strftime(fmt)
错误:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
AttributeError: 'long' object has no attribute 'astimezone
我想将此utc 1348283733848转换为人类可读格式的太平洋时区
答案 0 :(得分:0)
您可以使用
datetime.utctimestamp(now_utc).strftime("%H:%M:%S %Z%")