开发者

How to resolve this error - ValueError: time data did not match format:

开发者 https://www.devze.com 2023-03-20 18:20 出处:网络
I have a python code wh开发者_JAVA技巧ere I extract a date string (from a web page) which I then try to convert into a dateobject before using it. It has been working all along but since today I\'ve b

I have a python code wh开发者_JAVA技巧ere I extract a date string (from a web page) which I then try to convert into a dateobject before using it. It has been working all along but since today I've been getting this error

ValueError: time data did not match format:  data=Sun, 17 Jul 2011 23:51:19  fmt=%a, %d %b %Y %H:%M:%S

This is my code

myDate = --get date from user. Example is Sun, 17 Jul 2011 23:51:19---
#convert date from string
newDate = datetime.datetime.strptime(myDate,'%a, %d %b %Y %H:%M:%S')

I've checked the source of the date string and it is still formatted as Sun, 17 Jul 2011 23:51:19. Can anyone tell me what I am missing?

Thanks


Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> myDate = "Sun, 17 Jul 2011 23:51:19"
>>> datetime.datetime.strptime(myDate, '%a, %d %b %Y %H:%M:%S')
datetime.datetime(2011, 7, 17, 23, 51, 19)
>>> 

Are you sure the string is correct? Can you maybe print repr(myDate) to be sure?

0

精彩评论

暂无评论...
验证码 换一张
取 消