Skip to content

Instantly share code, notes, and snippets.

@miklevin
Last active July 26, 2019 17:27
Show Gist options
  • Save miklevin/c027312638ad15f1aafcaf0f18038c42 to your computer and use it in GitHub Desktop.
Save miklevin/c027312638ad15f1aafcaf0f18038c42 to your computer and use it in GitHub Desktop.
Get a timezone-aware local time object from Python
import pytz
import datetime
nowz = datetime.datetime.utcnow()
dt = nowz.astimezone(pytz.timezone('US/Eastern'))
print(dt.strftime('%Y-%m-%d %H:%M:%S %Z%z'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment