1、将字符串转化为时间:
from datetime import datetime
str_time = "2017-01-01 10:23:34"
time_time = datetime.strptime(str_time,"%Y-%m-%D %H:%M:%S")
结果:
2017-01-01 10:23:34
2、将时间转化为字符串:
from datetime import datetime
time_time = datetime.now()
str_time = time_time.strftime("%Y-%m-%D %H:%M:%S")
注:python 时间类型和相互转换:https://www.cnblogs.com/shhnwangjian/p/6117602.html