Hello,

I am writing a little script that needs to get the timezone from an rss feed, and I am using Feed Parser to parse the rss feeds. The way that I am converting the date into Unix Epoch time is:

feedDate = feed['feed'].get('updated_parsed') or feed.entries[0].get('updated_parsed')
feedDate = mktime(datetime(*feedDate[0:6]).timetuple())

This code doesn't take into account the timezone information, but I am wondering if it is possible to. Is there a way to modify my code so that it will?

Thank you,
Justin

It depends heavily on the format that you are receiving the time data in. Could you provide us with an example of EXACTLY what you are getting?
If it is coming in as a string with the Time Zone then iyou simply use time.strptime(), which will make it very easy for you.

I am going through a list of rss feeds and getting the date from each entry in the feed. I know that every rss feed isn't going to have the same convention for displaying the timezone so I'm hoping that the feedparser figures that out for you, but I don't know how to use that functionality (if it even exists).

But for example, entryDate[0:6] returns a tuple like (2008, 2, 27, 0, 15, 15). This doesn't contain any timezone information. entryDate follows the python time tuple convention, so you can't pull the timezone from there. I was looking at the feed parser reference page, and didn't see anything dealing with timezone but hopefully I am missing something (I would think that would be a pretty basic for such a commonly used script)

Thanks for your help,
Justin

Looking through the Date Parsing section of the feed parser reference page reveals the following: that the dateHandler functions "return a single value, a 9-tuple Python date in UTC".

Which means that the time that is returned is standardized to GMT (I still don't like the UTC naming convention)... If you would like to display it as a different timezone you will need to get the utc offset value and simply add it to the hours. Otherwise, I would just leave it in UTC so that all posts are standardized.

Ohh, I didn't see that, thank you! That makes things really easy.

Thanks again,
Justin

Sorry I'm back again, five days ago everything looked so good but now I am confused as ever.

Take for example the story "Police Secretly Planting GPS Devices On Cars" posted recently on Slashdot. It has a date of 2008-08-13T23:15:00+00:00. I am running the following code:

utcTime= mktime(datetime(*entryDate[0:6]).timetuple())

This code returns a time of 1218683700, while according to the date 2008-08-13T23:15:00+00:00 that number should be 1218669300, or four hours behind. Where are these four hours coming from?

Any help would greatly be appreciated (I'm pulling my hair out with this epoch time stuff)

Thanks,
Justin

According to
mktime takes struct_time in local time as per
"Use the following functions to convert between time representations:" section of the page

As Opsive wrote 10 posts 5 years ago, we guess that (s)he is not waiting for an answer today. Please don't revive old threads. Start your own thread instead.

Edited 2 Years Ago by Gribouillis

This question has already been answered. Start a new discussion instead.