xralf
xralf

Reputation: 3642

Convert string from feedparser to datetime

I'd like to convert the string obtained as follows into datetime:

d = feedparser.parse(xmlUrl)
t = datetime.strptime(d.feed.updated, "%Y-%m-%dT%H:%M:%SZ")

note the T and Z letters in the mask. They can be missing and I'm not sure what else can be in this format and how to create the mask to cover all possibilities.

The problem here is that the mask sometimes match and sometimes not. Could the matching be done to always match?

Upvotes: 1

Views: 1496

Answers (1)

Beat Bolli
Beat Bolli

Reputation: 441

You should use the parsed forms of the date fields: feed.updated_parsed contains a struct_time like the one returned by time.gmtime().

Upvotes: 3

Related Questions