python将字符串类型改成日期类型
将字符串类型的'2019-03-14'改成date类型,如下:
import datetime b = datetime.date(*map(int,'2019-03-14'.split('-'))) print(b,type(b))
将datetime类型转成str
form datetime import datetime str_date = datetime.now().strftime("%Y-%m-%d")
将str类型转成datetime
form datetime import datetime start_date = datetime.strptime("2019-04-15", "%Y-%m-%d")