Subtracting (Apache log) timestamp strings in python? -


i have apache log has timestamps like:

[03/feb/2013:02:52:05 +0000] 

as string. purposes trailing +0000 isn't needed. end goal time-difference between 2 time stamps in minutes. there more elegant, less verbose approach hacking , comparing elements in piecemeal, ripple-adding fashion?

ideally i'd little possible string before using initialize time object of sort, has 'compare_to( )' type method.

i'm relatively new python, i'm sorry if there's obvious library or approach this, haven't been able find one.

if don't need timezone offset, can use datetime module parse data:

from datetime import datetime  line = '[03/feb/2013:02:52:05 +0000]' date = line[1:line.find(' ')]   #  take string second character first blank line_timestamp = datetime.strptime(date, "%d/%b/%y:%h:%m:%s")  print repr(line_timestamp) # datetime.datetime(2013, 2, 3, 2, 52, 5) 

you can subtract values.


Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -