python 字符串转时间使用strptime()函数,此函数与strftime()函数完全相反,该函数将datetime对象转换为字符串。
此外,python的time模块和datetime模块
例如:
from datetime import datetime
datetime_str = '09/19/18 13:55:26'
datetime_object = datetime.strptime(datetime_str, '%m/%d/%y %H:%M:%S')
print(type(datetime_object))
print(datetime_object) # printed in default format
from datetime import datetime
def calTime(y,m,d):
datetime_str2 = str(int(y))+'-'+str(int(m))+'-'+str(int(d))
datetime_object2 = datetime.strptime(datetime_str2, '%Y-%m-%d')
return datetime_object2