如何在python中将字符串日期转换为日期时间格式? [英] how to convert a string date into datetime format in python?
本文介绍了如何在python中将字符串日期转换为日期时间格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在python中将一串日期时间转换为日期时间格式,以便与另一个日期进行比较?
How do I convert a a string of datetime into datetime format in python so that it can be compared with another date?
string_date = "2013-09-28 20:30:55.78200"
abc = datetime.datetime.now()
if abc > string_date :
print True
推荐答案
strptime
的特定格式:
datetime.datetime.strptime(string_date, "%Y-%m-%d %H:%M:%S.%f")
#>>> datetime.datetime(2013, 9, 28, 20, 30, 55, 782000)
这篇关于如何在python中将字符串日期转换为日期时间格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文