Python time.strptime()给出了错误的结果?

ner*_*com 1 python time strptime

我正在尝试解析mbox格式的电子邮件假脱机.

我有代码执行此操作:

if string.find(line, 'Date: ') == 0:                     
    try:
        when = time.mktime(time.strptime(line[6:30], "%a, %d %b %Y %H:%M:%S"))
Run Code Online (Sandbox Code Playgroud)

通常它似乎工作正常,除了当行='日期:星期六,2004年4月17日22:29:37 -0400 \n'它似乎给出了错误的结果(22:29:03而不是22:29:37 ).

这是我的pdb跟踪:

(Pdb) p line
'Date: Sat, 17 Apr 2004 22:29:37 -0400\n'
(Pdb) p time.strptime(line[6:30], "%a, %d %b %Y %H:%M:%S")
time.struct_time(tm_year=2004, tm_mon=4, tm_mday=17, tm_hour=22, tm_min=29, tm_sec=3, tm_wday=5, tm_yday=108, tm_isdst=-1)
(Pdb)
Run Code Online (Sandbox Code Playgroud)

结果似乎是34秒.我究竟做错了什么?

Mar*_*ers 7

你的线路太短了; 第二个值是独占的,不包括:

>>> line[6:30]
'Sat, 17 Apr 2004 22:29:3'
>>> line[6:31]
'Sat, 17 Apr 2004 22:29:37'
>>> time.strptime(line[6:31], "%a, %d %b %Y %H:%M:%S")
time.struct_time(tm_year=2004, tm_mon=4, tm_mday=17, tm_hour=22, tm_min=29, tm_sec=37, tm_wday=5, tm_yday=108, tm_isdst=-1)
Run Code Online (Sandbox Code Playgroud)