Skip to content

Instantly share code, notes, and snippets.

@unutbu
Created August 18, 2014 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unutbu/85d555969e304cedda2e to your computer and use it in GitHub Desktop.
Save unutbu/85d555969e304cedda2e to your computer and use it in GitHub Desktop.
import calendar
import pytz
import datetime as DT
tz1 = pytz.timezone('US/Eastern')
utc = pytz.timezone('UTC')
now = utc.localize(DT.datetime(2002, 10, 27, 7, 0, 0))
now_tz = now.astimezone(tz1)
now_epoch = calendar.timegm(now_tz.utctimetuple())
begin_day = now_tz.replace(hour=0, minute=0, second=0)
begin_day2 = tz1.normalize(begin_day)
assert begin_day.utctimetuple() == begin_day2.utctimetuple()
begin_epoch = calendar.timegm(begin_day.utctimetuple())
begin_epoch2 = calendar.timegm(begin_day2.utctimetuple())
assert begin_epoch == begin_epoch2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment