datetime.stdptime help
Mike Driscoll
kyosohma at gmail.com
Tue May 27 12:25:34 EDT 2008
On May 27, 10:34 am, Laszlo Nagy <gand... at shopzeus.com> wrote:
> def str2datetime(s):
> #28 May 2008 12:38:16 BDT
> return time.strptime(s,"%d %b %Y %H:%M:%S %Z")
>
> #.... some code here....
> print repr(pd)
> print str2datetime(pd)
>
> Result:
>
> '24 May 2008 12:38:16 BDT'
> Traceback (most recent call last):
> File "__init__.py", line 40, in <module>
> print ssc.get_order_data('202-9810306-3236320')
> File
> "/usr/local/www/vhosts/zeusd1/fantasy/controller/sites/ControllerBase.py",
> line 306, in get_order_data
> print str2datetime(pd)
> File
> "/usr/local/www/vhosts/zeusd1/fantasy/controller/sites/ControllerBase.py",
> line 299, in str2datetime
> return time.strptime(s,"%d %b %Y %H:%M:%S %Z")
> File "/usr/local/lib/python2.5/_strptime.py", line 331, in strptime
> (data_string, format))
> ValueError: time data did not match format: data=24 May 2008 12:38:16
> BDT fmt=%d %b %Y %H:%M:%S %Z
>
> I think that the format is correct. What am I doing wrong?
>
> Thanks,
>
> Laszlo
I tried taking out components until I got it to work. It seems to be
choking on the time zone part of it. If you remove the "BDT" from your
string and the "%Z" from your formatter, it works. Unfortunately, I do
not know why it doesn't work the other way.
Mike
More information about the Python-list
mailing list