0

I am new at Python. I was trying to play with time and date objects. I wrote a simple test program to parse a string into a specific time format. But its throwing a ValueError. Can you please help me out here?

Here is the code:

import time
testDate = "Tuesday, Febuary 23 2011 12:00:00 UTC"
today = time.strptime(testDate,"%A, %B %d %Y %H:%M:%S %Z")
print today

and the error:

Traceback (most recent call last):
  File "D:\Python\PythonTest\src\helloWorld.py", line 3, in <module>
    today = time.strptime(testDate,"%A, %B %d %Y %H:%M:%S %Z")
  File "C:\Python27\Lib\_strptime.py", line 467, in _strptime_time
    return _strptime(data_string, format)[0]
  File "C:\Python27\Lib\_strptime.py", line 325, in _strptime
   (data_string, format))
ValueError: time data 'Tuesday, Febuary 23 2011 12:00:00 UTC' does not match format '%A, %B %d %Y %H:%M:%S %Z'
planet260
  • 1,384
  • 1
  • 14
  • 30

2 Answers2

3

You had February misspelled. Your code works.

import time
testDate = "Tuesday, February 23 2011 12:00:00 UTC"
today = time.strptime(testDate,"%A, %B %d %Y %H:%M:%S %Z")
print today
badc0re
  • 3,333
  • 6
  • 30
  • 46
  • "Febuary" Ok that was unfortunate.. Actually i am getting time from RSS Feed and its throwing this error. I changed the date to testDate = "Tuesday, January 24 2012 13:00:00 EST" This is the exact date from RSS feed and again i get the above error. – planet260 Aug 26 '13 at 15:37
  • Here is the similar problem http://stackoverflow.com/questions/3305413/python-strptime-and-timezones – badc0re Aug 26 '13 at 15:43
1

Very simple: you spelled "February" wrong:

import time
testDate = "Tuesday, February 23 2011 12:00:00 UTC"
today = time.strptime(testDate,"%A, %B %d %Y %H:%M:%S %Z")
print today

Originally, you had "February" spelled as "Febuary". Works fine once that is fixed.

  • "Febuary" Ok that was unfortunate.. Actually i am getting time from RSS Feed and its throwing this error. I changed the date to testDate = "Tuesday, January 24 2012 13:00:00 EST" This is the exact date from RSS feed and again i get the above error. – planet260 Aug 26 '13 at 15:39
  • @planet260 - I fixed _that_ error by changing "EST" to "UTC". Apparently, the system only works in UTC time. –  Aug 26 '13 at 15:46