datetime - Why %z is not supported by python's strptime? -


>>> datetime.strptime('2014-02-13 11:55:00 -0800', '%y-%m-%d %h:%m:%s %z') traceback (most recent call last):   file "<stdin>", line 1, in <module>   file "/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/_strptime.py", line 317, in _strptime     (bad_directive, format)) valueerror: 'z' bad directive in format '%y-%m-%d %h:%m:%s %z' 

i understand it's not supported, don't know why. seems it's not hard support that. , 'offset utc' not ambiguous timezone abbreviation.

until python 3.2, python's datetime module had no timezone() object. supported 3rd-party libraries providing timezones providing datetime.tzinfo() abstract base class, no timezone object included. without timezone object, no support parsing timezone offsets either.

as of python 3.2, z supported, because version (and up) added datetime.timezone() type:

>>> import datetime >>> datetime.datetime.strptime('2014-02-13 11:55:00 -0800', '%y-%m-%d %h:%m:%s %z') datetime.datetime(2014, 2, 13, 11, 55, tzinfo=datetime.timezone(datetime.timedelta(-1, 57600))) >>> _.tzinfo datetime.timezone(datetime.timedelta(-1, 57600)) 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -