pytz library
- Install
pytz
library from the command line:
pip install pytz
- Get time zone offset in seconds by time zone name:
import datetime
import pytz
def getTimezoneOffset(timezone):
tz = pytz.timezone(timezone)
dt = datetime.datetime.now(tz)
return int(dt.utcoffset().total_seconds())
print(getTimezoneOffset('America/New_York')) # -14400
Leave a Comment
Cancel reply