0

I have some IIS(Internet Information Service) logs that I need to process, something like the Apache web log if you are a Linux server guy.

The web logs starts with:

49.76.xx.xx - - [01/Jun/2015:00:01:08 -0500] "GET...

And I am curious about the timestamp, [01/Jun/2015:00:01:08 -0500], what does 0500 mean in this scenario? is it something like the timezone or offset based on this python documentation?

This is what I have done so far but it doesn't work:

from datetime import datetime
text = "01/Jun/2015:00:01:08 +0500"
print datetime.strptime(text, '%d/%b/%Y:%H:%M:%S %z')

And here is the error message.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-10-e243ceb157eb> in <module>()
      1 from datetime import datetime
      2 text = "01/Jun/2015:00:01:08 +0500"
----> 3 print datetime.strptime(text, '%d/%b/%Y:%H:%M:%S %z')

/opt/local/anaconda/lib/python2.7/_strptime.pyc in _strptime(data_string, format)
    315                 del err
    316                 raise ValueError("'%s' is a bad directive in format '%s'" %
--> 317                                     (bad_directive, format))
    318             # IndexError only occurs when the format string is "%"
    319             except IndexError:

ValueError: 'z' is a bad directive in format '%d/%b/%Y:%H:%M:%S %z'
B.Mr.W.
  • 18,910
  • 35
  • 114
  • 178
  • `-0500` is a *time zone offset*, which means that this specific local time was 5 hours behind UTC. Do not confuse *offset* with *time zone*, as many time zones change their offsets for daylight saving time and other anomalies. Also, be careful - you show `-0500` in one case, and `+0500` in another. Those are 10 hours apart from each other. – Matt Johnson-Pint Dec 24 '15 at 21:34

1 Answers1

0

%z represents the timezone..you cannot use %z with .strptime() .. you might consider using pytz module for timezone

repzero
  • 8,254
  • 2
  • 18
  • 40