4 ms·
Use pytz. import pytz from datetime import datetime tz = pytz.timezone('Asia/Shanghai') tz.normalize(pytz.utc.localize(datetime.utcnow()).astimezone(t
by wulczer 15y ago
Use pytz.
import pytz
from datetime import datetime
tz = pytz.timezone('Asia/Shanghai')
tz.normalize(pytz.utc.localize(datetime.utcnow()).astimezone(tz))
- riobard 15y agoThanks for the response! I'm looking for a solution such that Python will go and load system's time zone and use that---it's a nightmare to deploy an app to multiple severs located in different timezone and I have to change the timezone in Python manually.