Convert and convert back datetime in Django
-
25-05-2021 - |
سؤال
I am parsing feeds using feedparser and I am trying to store updated or updated_parsed attributes of feeds in Django db.
But it shows an error as [u'Enter a valid date/time in YYYY-MM-DD HH:MM[:ss[.uuuuuu]] format.']
Please tell me how to convert updated and updated_parsed such that it can be stored in the Django db such that I can (convert and reuse) or just reuse the date stored in db while parsing in this way:
feedparser.parse("url", modified = lastupdate)
المحلول 2
import time, datetime, feedparser, calendar
feed = feedparser.parse('www.popgadget.net')
feed_updated_date = datetime.datetime.utcfromtimestamp(calendar.timegm(feed.feed.updated_parsed))
نصائح أخرى
Have you looked at datetime object?
You will need to use strptime()
and strftime()
to convert datetimes.
http://docs.python.org/library/datetime.html#strftime-strptime-behavior
لا تنتمي إلى StackOverflow