Skip to content

Instantly share code, notes, and snippets.

@sungitly
Created March 5, 2015 05:00
Show Gist options
  • Save sungitly/e36fdb73c3146bd02e01 to your computer and use it in GitHub Desktop.
Save sungitly/e36fdb73c3146bd02e01 to your computer and use it in GitHub Desktop.
Convert String Datetime To Unix Time
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