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