Skip to content

Instantly share code, notes, and snippets.

@n1chre
Created June 28, 2018 16:56
Show Gist options
  • Save n1chre/e67ecceec6b4fc23a7a5b94c958c1a1f to your computer and use it in GitHub Desktop.
Save n1chre/e67ecceec6b4fc23a7a5b94c958c1a1f to your computer and use it in GitHub Desktop.
Transform a timestamp into int (microseconds precision)
import time
import datetime
timestamp_format = '%Y-%m-%d %H:%M:%S,%f' # 2018-06-28 13:34:04,776
epoch = datetime.datetime.utcfromtimestamp(0) # timestamp at 1970-01-01 00:00:00
def timestamp_to_int(ts):
dt = datetime.datetime.strptime(ts, timestamp_format)
return int((dt-epoch).total_seconds()*1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment