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?
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)