首先引入:
import datetime
import time
1、string转datetime
str = '2012-11-19'
date_time = datetime.datetime.strptime(str,'%Y-%m-%d')
2、datetime转string
date_time=datetime.datetime(2012,11,19,0,0)
date_time.strftime('%Y-%m-%d')
3、datetime转时间戳
date_time=2012-11-19'
time_time = time.mktime(date_time.timetuple())
4、时间戳转string
time_time=1353254400.0
time.strftime('%Y-%m-%d',time.localtime(time_time))