简体   繁体   English

Python,将9元组UTC日期转换为MySQL日期时间格式

[英]Python, Convert 9 tuple UTC date to MySQL datetime format

I am parsing RSS feeds with the format as specified here: http://www.feedparser.org/docs/date-parsing.html 我正在使用此处指定的格式解析RSS提要: http//www.feedparser.org/docs/date-parsing.html

date tuple (2009, 3, 23, 13, 6, 34, 0, 82, 0) 日期元组(2009,3,23,13,6,34,0,82,0)

I am a bit stumped at how to get this into the MySQL datetime format (Ymd H:M:S)? 我有点难以理解如何将其转换为MySQL日期时间格式(Ymd 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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM