fork download
  1. from datetime import datetime
  2. from dateutil import tz
  3.  
  4. # METHOD 1: Hardcode zones:
  5. from_zone = tz.gettz('UTC')
  6. to_zone = tz.gettz('America/New_York')
  7.  
  8. # METHOD 2: Auto-detect zones:
  9. from_zone = tz.tzutc()
  10. to_zone = tz.tzlocal()
  11.  
  12. # utc = datetime.utcnow()
  13. utc = datetime.strptime('2011-01-21 02:37:21', '%Y-%m-%d %H:%M:%S')
  14.  
  15. # Tell the datetime object that it's in UTC time zone since
  16. # datetime objects are 'naive' by default
  17. utc = utc.replace(tzinfo=from_zone)
  18.  
  19. # Convert time zone
  20. central = utc.astimezone(to_zone)
Success #stdin #stdout 0.03s 8732KB
stdin
Standard input is empty
stdout
Standard output is empty