Python, Convert 9 tuple UTC date to MySQL datetime format

∥☆過路亽.° 提交于 2019-12-10 02:31:02

问题


I am parsing RSS feeds with the format as specified here: http://www.feedparser.org/docs/date-parsing.html

date tuple (2009, 3, 23, 13, 6, 34, 0, 82, 0)

I am a bit stumped at how to get this into the MySQL datetime format (Y-m-d H:M:S)?


回答1:


tup = (2009, 3, 23, 13, 6, 34, 0, 82, 0)
import datetime 
d = datetime.datetime(*(tup[0:6]))
#two equivalent ways to format it:
dStr = d.isoformat(' ')
#or
dStr = d.strftime('%Y-%m-%d %H:%M:%S')


来源:https://stackoverflow.com/questions/686717/python-convert-9-tuple-utc-date-to-mysql-datetime-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!