Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Convert local date to midnight UTC timestamp
import pytz
from datetime import date, datetime, time
def today_to_midnight_utc(local_tz='UTC'):
Returns today's date (local timezone) as a midnight UTC timestamp.
e.g. If date is 04/20/18, and server timezone is America/Los_Angeles:
>> 1524182400
tz = pytz.timezone(local_tz)
local_date =
midnight_no_tz = datetime.combine(local_date, time())
midnight_tz = tz.localize(midnight_no_tz)
midnight_utc = midnight_tz.astimezone(pytz.utc)
return int(midnight_utc.timestamp())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.