1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| 字符串转换成datetime对象
from datetime import datetime # 导入datetime模块 value = '2017/10/7' datetime.strptime(value, '%Y/%m/%d')
datetime对象转换成字符串
from datetime import datetime # 导入datetime模块 stamp = datetime(2017, 10, 7) # 生成一个datetime对象 str(stamp) # 转换 #结果显示:'2017-10-07 00:00:00'
from datetime import datetime # 导入datetime datetime.datetime转化成字符串 create_time.strftime('%Y-%m-%d %H:%M:%S')
|