格式化输出时间,时间转字符串
import datetime
# des: 可以修改里面的间隔符号,如 %Y/%m/%d %H:%M:%S 等,格式化输出后type为 'str'
result = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
# 输出结果: 2019-04-04 08:00:00
tmp = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S').split('-')
result1 = '{}年{}月{}日 {}时{}分{}秒'.format(tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5])
# 输出结果: 2019年04月04日 08时00分00秒
字符串str转datetime.datetime
import datetime
# des: 最后输出type为 'datetime.datetime'
str_time = '2019-04-04 08:00:00'
result = datetime.datetime.strptime(str_time, '%Y-%m-%d %H:%M:%S')
# 输出结果: 2019-04-04 08:00:00
str_time1 = '2019年04月04日 08时00分00秒'
result1 = datetime.datetime.strptime(str_time1, '%Y年%m月%d日 %H时%M分%S秒')
# 输出结果: 2019-04-04 08:00: