2 回答

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超6個(gè)贊
from datetime import datetime
import pytz
tz_NY = pytz.timezone('America/New_York')
datetime_NY = datetime.now(tz_NY)
print("NY time:", datetime_NY.strftime("%H:%M:%S"))
簡(jiǎn)單的方法是,
from datetime import datetime, timezone
utc_dt = datetime.now(timezone.utc)
print("Local time {}".format(utc_dt.astimezone().isoformat()))

TA貢獻(xiàn)1752條經(jīng)驗(yàn) 獲得超4個(gè)贊
Python 文檔推薦使用該pytz模塊。
pip install pytz
>>> import datetime
>>> import pytz
>>> dt_now = datetime.datetime.now(tz = pytz.UTC)
>>> print(dt_now)
2020-08-09 07:02:20.863890+00:00
添加回答
舉報(bào)