2024-04-20 03:39:20 发布
网友
如何在python中将datetime字符串转换为datetime格式,以便与其他日期进行比较?
string_date = "2013-09-28 20:30:55.78200" abc = datetime.datetime.now() if abc > string_date : print True
strptime的特定格式:
strptime
datetime.datetime.strptime(string_date, "%Y-%m-%d %H:%M:%S.%f") #>>> datetime.datetime(2013, 9, 28, 20, 30, 55, 782000)
您应该使用^{}:
import datetime dt = datetime.datetime.strptime(string_date, fmt)
fmt必须是字符串的适当格式。你会找到reference on how to build your format here。
fmt
strptime
的特定格式:您应该使用^{} :
fmt
必须是字符串的适当格式。你会找到reference on how to build your format here。相关问题 更多 >
编程相关推荐