【问题标题】:IIS log timestap timezone [duplicate]IIS日志时间戳时区[重复]
【发布时间】:2015-12-24 21:04:03
【问题描述】:

我有一些 IIS(Internet 信息服务)日志需要处理,如果您是 Linux 服务器人员,则类似于 Apache Web 日志。

网络日志以:

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

我很好奇时间戳,[01/Jun/2015:00:01:08 -0500],在这种情况下 0500 是什么意思?它是基于this python 文档的时区或偏移量吗?

这是我到目前为止所做的,但它不起作用:

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

这是错误消息。

---------------------------------------------------------------------------
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'

【问题讨论】:

  • -0500 是一个时区偏移,这意味着这个特定的本地时间比 UTC 晚 5 小时。不要将 offsettime zone 混淆,因为许多时区会根据夏令时和其他异常情况更改它们的偏移量。另外,请注意 - 您在一种情况下显示-0500,在另一种情况下显示+0500。它们相隔 10 个小时。

标签: python datetime iis


【解决方案1】:

%z 代表时区..您不能将%z.strptime() 一起使用..您可以考虑使用pytz 模块作为时区

【讨论】:

    猜你喜欢
    • 2012-09-10
    • 2018-05-10
    • 2011-09-07
    • 2011-02-26
    • 1970-01-01
    • 2015-02-16
    • 2015-08-30
    • 2016-11-06
    • 1970-01-01
    相关资源
    最近更新 更多