Python字符串和日期相互转换的方法

 

import time,datetime
# 日期转换成字符串 print time.strftime("%Y-%m-%d %X", time.localtime())
#字符串转换成日期 t = time.strptime("2009 - 08 - 08", "%Y - %m - %d") y,m,d = t[0:3]
print datetime.datetime(y,m,d)
输出结果为:
2015-05-13 10:43:07 2009-08-08 00:00:00

 

posted @ 2017-05-10 17:43  村里汉子  阅读(610)  评论(0编辑  收藏  举报