Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3349320
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:39:01+00:00 2026-05-18T01:39:01+00:00

I am using python’s feedparser module, to parse an RSS feed. Once parsed, feedparser

  • 0

I am using python’s feedparser module, to parse an RSS feed. Once parsed, feedparser returns dates in a python 9 tuple time format (time.struct_time).

I am want to store these values in my mysql database so I can later check the Last-Modified headers of the feed. It’s import that if the times tuples are converted, that when converted back they stay the same, so I can later use them for comparison.

I tried this to convert the time tuple to datetime and then back, but it wasn’t the same when converted back:

dt = datetime.fromtimestamp(time.mktime(struct))
time_tuple = dt.timetuple()

What do you think is the method to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:39:01+00:00Added an answer on May 18, 2026 at 1:39 am

    I believe the reason why your method is not preserving the time tuple is because the is_dst value was changed. time.mktime respected the is_dst in struct, but dt.timetuple changes is_dst to -1.

    One way to avoid this error would be to interprets the time tuple as representing a UTC time. That may not be strictly correct, but it may be good enough for your purposes.

    In [1]: import datetime as dt
    In [2]: import time
    In [3]: import calendar
    
    In [17]: time_tuple=(1970, 1, 1, 0, 0, 0, 3, 1, 1)
    
    In [18]: timestamp=calendar.timegm(time_tuple)
    In [19]: timestamp
    Out[19]: 0
    
    In [20]: date=dt.datetime.utcfromtimestamp(timestamp)
    In [21]: date
    Out[21]: datetime.datetime(1970, 1, 1, 0, 0)
    
    In [22]: tuple(date.timetuple())
    Out[22]: (1970, 1, 1, 0, 0, 0, 3, 1, -1)
    

    PS. Here is an example showing how the method you posted might fail to preserve the time tuple. Suppose the remote server is in a locale where is_dst = 1, while is_dst = 0 in your locale:

    In [11]: time_tuple=(1970, 1, 1, 0, 0, 0, 3, 1, 1)
    
    In [12]: timestamp=time.mktime(time_tuple)
    In [13]: timestamp
    Out[13]: 14400.0
    
    In [14]: date=dt.datetime.fromtimestamp(timestamp)
    In [15]: date
    Out[15]: datetime.datetime(1969, 12, 31, 23, 0)
    
    In [16]: tuple(date.timetuple())
    Out[16]: (1969, 12, 31, 23, 0, 0, 2, 365, -1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Python I want to be able to draw text at different angles using
Using python 2.4 and the built-in ZipFile library, I cannot read very large zip
Using Python, how would I go about reading in (be from a string, file
Using Python 2.6, is there a way to check if all the items of
Using Python's Imaging Library I want to create a PNG file. I would like
When using Python's super() to do method chaining, you have to explicitly specify your
I want to start using Python for small projects but the fact that a
I'm using python and CherryPy to create a simple internal website that about 2
I am using python 2.6 on XP. I have just installed py2exe, and I
I'm using python and I need to map locations like Bloomington, IN to GPS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.