I need to get the published field of an RSS feed, and I need to know what the timezone is. I am storing the date in UTC, and I want another field to store the timezone so that I can later manipulate the datetime.
My current code is as follows:
for entry in feed['entries']:
if hasattr(entry, 'published'):
if isinstance(entry.published_parsed, struct_time):
dt = datetime(*entry.published_parsed[:-3])
The final value of dt is the correct datetime in UTC, but I need also to get the original timezone. Can anyone help?
EDIT:
For future reference, even though it is not part of my original question, if you need to manipulate a non standard timezone (like est), you need to make a conversion table per your specification. Thanks to this answer: Parsing date/time string with timezone abbreviated name in Python?
You can use
parser.parse
method ofdateutil
package.For example for statckoverflow:
You can see that
published
ends withZ
, it means timezone is in UTC:Looks at History of Date Formats for it in feedparser:
And for another example:
But also it depends on the format of time data that received and type of feed.