用Python实现字符串和日期相互转换的方法,具体如下:
这里用的分别是time和datetime函数来处理
import time,datetime
//日期转化为字符串
# date to str
//输出时间
print time.strftime("%Y-%m-%d %X", time.localtime())
#str to date
//字符串转化为日期
t = time.strptime("2016 - 12 - 05", "%Y - %m - %d")
y,m,d = t[0:3]
//输出时间
print datetime.datetime(y,m,d)