Get Current Date and Time for Given Time Zone using Python

pytz library

  1. Install pytz library from the command line:
pip install pytz
  1. Convert date and time from one time zone to another:
import datetime
import pytz

dateTimeFormat = '%Y-%m-%d %H:%M:%S'

tz = pytz.timezone('America/New_York')
dt = datetime.datetime.now(tz)

dateTime = dt.strftime(dateTimeFormat)

print(dateTime)

Leave a Comment

Cancel reply

Your email address will not be published.