Skip to content

Instantly share code, notes, and snippets.

@mattbillenstein
Created March 9, 2019 20:34
Show Gist options
  • Save mattbillenstein/6a04c6ae1a771efd704543c21c8a8a89 to your computer and use it in GitHub Desktop.
Save mattbillenstein/6a04c6ae1a771efd704543c21c8a8a89 to your computer and use it in GitHub Desktop.
>>> import datetime
>>> import pytz
>>> tz = pytz.timezone('America/Los_Angeles')
>>> dt = datetime.datetime.utcnow()
>>> tz.localize(dt) + datetime.timedelta(days=2)
datetime.datetime(2019, 3, 11, 20, 32, 13, 824846, tzinfo=<DstTzInfo 'America/Los_Angeles' PST-1 day, 16:00:00 STD>)
>>> (tz.localize(dt) + datetime.timedelta(days=2)).isoformat()
'2019-03-11T20:32:13.824846-08:00'
>>> (tz.localize(dt + datetime.timedelta(days=2))).isoformat()
'2019-03-11T20:32:13.824846-07:00'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment