输入为:2011-01-01 输出为:2011-01-01 00:00:00
它是如何将它输出到:2011-01-01??在
# Packages
import datetime
def ObtainDate():
global d
isValid=False
while not isValid:
userInDate = raw_input("Type Date yyyy-mm-dd: ")
try: # strptime throws an exception if the input doesn't match the pattern
d = datetime.datetime.strptime(userInDate, '%Y-%m-%d')
isValid=True
except:
print "Invalid Input. Please try again.\n"
return d
print ObtainDate()
实际上和参考文献不一样。我只是问日期,不是时间。在
只需使用所需的格式设置解析对象的格式。在
在
^{pr2}$…实际上,如果您根本不想更改格式,请执行以下操作:
事实上,如果您想要速度,您可以完全跳过
datetime
:相关问题 更多 >
编程相关推荐