Skip to content

Instantly share code, notes, and snippets.

@hokie-sam
Last active March 5, 2018 17:16
Show Gist options
  • Select an option

  • Save hokie-sam/8dfa60617df750af529fea6b24d14bf9 to your computer and use it in GitHub Desktop.

Select an option

Save hokie-sam/8dfa60617df750af529fea6b24d14bf9 to your computer and use it in GitHub Desktop.
import time
from datetime import datetime
# It took me a while to figure out to convert
# a string timestamp to the number of seconds
# since the Unix epoch. Turns out it is pretty
# simple.
# Note: it only works for years >= 1900
my_td_string = 'Date: 2018-01-19 Time: 06:35:30.123'
datetime.strptime(my_td_string, 'Date: %Y-%m-%d Time: %H:%M:%S.%f').timestamp()
# Returns 1516361730.123
# For a full list of format codes, visit:
# https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment