Convert Snort string to Python timestamp

441 views Asked by At

I'm using Snort, which generates timestamps in MM-DD/time format, such as:

06/18-19:31:05.688344

I want to convert this to a Python timestamp, including the current year. What's the most pythonic way?

2

There are 2 answers

0
TigerhawkT3 On BEST ANSWER

Use the datetime module's strptime function.

>>> import datetime
>>> datetime.datetime.strptime(str(datetime.datetime.now().year) +
... '/' + '06/18-19:31:05.688344', '%Y/%m/%d-%H:%M:%S.%f')
datetime.datetime(2015, 6, 18, 19, 31, 5, 688344)
0
AudioBubble On

Check out snorts configuration. In the output section you can setup "seconds" as an output field. This is the timestamp in unix format which is better to work with. If u still need to convert it :

datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')