2013-09-28 61 views

回答

151

strptime的特定格式:

datetime.datetime.strptime(string_date, "%Y-%m-%d %H:%M:%S.%f") 
#>>> datetime.datetime(2013, 9, 28, 20, 30, 55, 782000) 
+0

%f支持哪些平台? –

+0

@JonathanLeaders我建议你问一个单独的问题。 – Veedrac

22

你应该使用datetime.datetime.strptime

import datetime 

dt = datetime.datetime.strptime(string_date, fmt) 

fmt将需要为您的字符串适当的格式。你会找到reference on how to build your format here

+0

你的意思是说'DT = datetime.datetime.strptime(string_date, “YYYY-MM-DD%H:%M%:%S”)'? – PythonEnthusiast

+0

@ user1162512该格式不正确,请检查我的更新答案。 –

+1

不适用于'dt = datetime.datetime.strptime(string_date,“YYYY-MM-DD%H:%M%:%S”)''。说格式无效 – PythonEnthusiast

相关问题