Created
March 5, 2015 05:00
-
-
Save sungitly/e36fdb73c3146bd02e01 to your computer and use it in GitHub Desktop.
Convert String Datetime To Unix Time
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
DATE_FORMATTER = '%Y-%m-%d %H:%M:%S' | |
def unix_time(dt): | |
epoch = datetime.utcfromtimestamp(0) | |
delta = dt - epoch | |
return delta.total_seconds() | |
def unix_time_millis(dt): | |
return unix_time(dt) * 1000.0 | |
print int(unix_time_millis(datetime.strptime(value, DATE_FORMATTER))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment