Skip to content

Instantly share code, notes, and snippets.

@bryder
Last active February 16, 2017 20:08
Show Gist options
  • Save bryder/0918d5b2de782849cd3043d71de5849a to your computer and use it in GitHub Desktop.
Save bryder/0918d5b2de782849cd3043d71de5849a to your computer and use it in GitHub Desktop.
Using arrow
# http://arrow.readthedocs.io/en/latest/
# when you to('local') you are taking utc and applying the localtime offset
# to it - and adding the local timezone descriptor to the object
now = arrow.utcnow().to('local')
# plural means add or subtract from
# singular means set to
# nice!
two_days_ago_rounded = now.replace(days=-2, hour=0, minute=0, second=0, microsecond=1)
# Setting the timezone on a time - this does not convert it!
# It marks the object as being in the requested timezone.
two_days_ago_rounded.replace(tzinfo=tz.tzlocal())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment