Skip to content

Instantly share code, notes, and snippets.

@StickmanNinja
Created June 23, 2019 23:09
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 StickmanNinja/ecd7a8ee8816a838b202fbc44e1f4979 to your computer and use it in GitHub Desktop.
Save StickmanNinja/ecd7a8ee8816a838b202fbc44e1f4979 to your computer and use it in GitHub Desktop.
This python short function returns the epoch timestamp for a given date.
def convertGivenTimeToEpoch(year, month, day, hour, minute, ampm):
from datetime import *
m2 = str(hour) + ":" + str(minute) + " " + str(ampm.lower())
m2 = datetime.strptime(m2, '%I:%M %p')
m2 = str(m2)
m2 = m2.split(" ")[1]
m2.split(":")
time2 = datetime.datetime(1970,1,1,0,0,0)
time1 = datetime.datetime(year, month, day, m2[0], m2[1], m2[2])
x = (time1 - time2).total_seconds()
return x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment