[issue12886] datetime.strptime parses input wrong

STINNER Victor report at bugs.python.org
Fri Sep 2 16:54:19 CEST 2011


STINNER Victor <victor.stinner at haypocalc.com> added the comment:

Example:
---
import datetime

def test(text):
    try:
        d = datetime.datetime.strptime(text, '%Y%m%dT%H%M')
    except ValueError:
        pass
    else:
        print("%s without seconds => %s" % (text, d))
        return
    d = datetime.datetime.strptime(text, '%Y%m%dT%H%M%S')
    print("%s with seconds => %s" % (text, d))

test('20110817T1234')
test('20110817T12345')
test('20110817T123456')
---

Output:

20110817T1234 without seconds => 2011-08-17 12:34:00
20110817T12345 with seconds => 2011-08-17 12:34:05
20110817T123456 with seconds => 2011-08-17 12:34:56

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12886>
_______________________________________


More information about the Python-bugs-list mailing list