格式化時(shí)間正確操作方式
描述: 給你一個(gè)時(shí)間t(t是一個(gè)字典,共有六個(gè)字符串key(year,month,day,hour,minute,second),值為每個(gè)值為數(shù)字組成的字符串, 如t={'year':'2013','month':'9','day':'30','hour':'16','minute':'45','second':'2'}
請(qǐng)將其按照以下格式輸出, 格式:XXXX-XX-XX XX:XX:XX。如上例應(yīng)該輸出: 2013-09-30 16:45:02。
from __future__ import print_funcTIon import dateTIme,TIme,calendar # t={'year':'2013','month':'9','day':'30','hour':'16','minute':'45','second':'2'} def convert_to_date_TIme(t): nowdate = datetime.datetime(int(t['year']), int(t['month']), int(t['day']), int(t['hour']), int(t['minute']), int(t['second'])) # date_time = time.strptime(nowdate, "%Y-%m-%d %H:%M:%S") return nowdate print(convert_to_date_time(t), end='')