Get Time Zone Offset in Seconds by Time Zone Name using Python

pytz library

  1. Install pytz library from the command line:
pip install pytz
  1. 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

Your email address will not be published.