Created
June 28, 2018 16:56
-
-
Save n1chre/e67ecceec6b4fc23a7a5b94c958c1a1f to your computer and use it in GitHub Desktop.
Transform a timestamp into int (microseconds precision)
This file contains 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
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