Python 日期与字符串互转

1、str -> date

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

2、date -> str

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

你可能感兴趣的:(Python 日期与字符串互转)