Python中将带空格的字符串转换为MySql的DateTime的最有效方法 [英] Most Efficient Way in Python to Convert String with Whitespaces to DateTime for MySql

查看:57
本文介绍了Python中将带空格的字符串转换为MySql的DateTime的最有效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下字符串格式的数据"dd Mmm YYYY,HH:mm"(例如"2008年8月7日,16:25")

I have data that comes in the following string format "dd Mmm YYYY, HH:mm" (e.g. "07 Aug 2008, 16:25")

对于MySQL,最有效的方法是用Python将其转换为日期时间字符串格式"YYYY-MM-DD HH:MM:SS"吗?

What is the most efficient way to convert this in Python into the datetime string format "YYYY-MM-DD HH:MM:SS" for MySQL?

推荐答案

您是说用Python隐蔽吗?

Do you mean do the covert in Python?

>>> from datetime import datetime
>>> t = datetime.strptime('07 Aug 2008, 16:25', '%d %b %Y, %H:%M')
>>> t.strftime('%Y-%m-%d %H:%M:%S')
'2008-08-07 16:25:00'
>>> 

查看文档以获取更多详细信息.

Check the document for more details.

这篇关于Python中将带空格的字符串转换为MySql的DateTime的最有效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆