Last active
August 29, 2015 14:08
-
-
Save jjmalina/3e896cf26486ebf416fb to your computer and use it in GitHub Desktop.
Because I keep forgetting this...
This file contains hidden or 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
datetime_to_epoch | |
~~~~~~~~~~~~~~~~~ | |
Takes a (naive) UTC datetime and converts to epoch | |
""" | |
from calendar import timegm | |
def to_epoch(dt): | |
"""Returns the UTC epoch given a datetime | |
""" | |
return timegm(dt.utctimetuple()) | |
if __name__ == '__main__': | |
import sys | |
from dateutil.parser import parse | |
if len(sys.argv) > 1: | |
for date in sys.argv[1:]: | |
print to_epoch(parse(date)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment