Last active
September 14, 2015 08:54
-
-
Save victorkristof/eb3512e16f8308b7dd1f to your computer and use it in GitHub Desktop.
Convert Python datetime into timestamp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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