Python,将9元组UTC日期转换为MySQL datetime格式 [英] Python, Convert 9 tuple UTC date to MySQL datetime format
本文介绍了Python,将9元组UTC日期转换为MySQL datetime格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用如下指定的格式解析RSS资讯提供: http:// www。 feedparser.org/docs/date-parsing.html
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 )
date tuple (2009, 3, 23, 13, 6, 34, 0, 82, 0)
我有点困惑,如何将其转化为MySQL datetime格式(Ymd H:M:S)?
I am a bit stumped at how to get this into the MySQL datetime format (Y-m-d H:M:S)?
推荐答案
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')
这篇关于Python,将9元组UTC日期转换为MySQL datetime格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文