Skip to content

Instantly share code, notes, and snippets.

@victorkristof
Last active September 14, 2015 08:54
Show Gist options
  • Save victorkristof/eb3512e16f8308b7dd1f to your computer and use it in GitHub Desktop.
Save victorkristof/eb3512e16f8308b7dd1f to your computer and use it in GitHub Desktop.
Convert Python datetime into timestamp
def datetime_to_timestamp(dt, epoch=datetime(1970, 1, 1)):
"""
Convert datetime into timestamp (in seconds).
:param dt: Datetime object to convert
:param epoch: Base Epoch to be counted from, default is 01.01.1970
:return: Number of seconds since the Epoch
"""
return int((dt - epoch).total_seconds())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment