「Python」python日期与字符串互转

1str -> date

import datetime

detester = ‘2017-01-01'
date = datetime.datetime.strptime(detester,’%Y-%m-%d')

2date -> str

import datetime

date = datetime.now()

detester = date.strftime(‘%Y-%m-%d')

--------------------- 本文来自 criller 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/criller/article/details/73715057?utm_source=copy 

PS:若时间格式为前段传回,有可能字符串后面有空格,会报错。可len()查看处理

原文地址:https://www.cnblogs.com/wrxblog/p/9719881.html