Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Parse datetime string with and without timezone information

  • strptime
  • tzinfo
import datetime

dt = datetime.datetime.strptime('Jun 7, 2022', '%b %d, %Y')
print(dt)
print(dt.tzinfo)


dt_utc = datetime.datetime.strptime('Jun 7, 2022 +0000', '%b %d, %Y %z')
print(dt_utc)
print(dt_utc.tzinfo)