2016-11-11 196 views

回答

0

作爲錯誤指示

TypeError: strptime() argument 1 must be string, not tuple

selected_time = datetime.strptime((current_date, time_input),"%Y/%m/%d %H:%M:%S.%f") 

第一個參數應該是一個字符串,但是您傳遞的是一個元組(current_date, time_input)

由於要對時間和日期分別接受輸入,則可以使用'%s %s' % (current_date, time_input)加入其中,然後將其傳遞給datetime.strptime如下

selected_time = datetime.strptime( 
    '%s %s' % (current_date, time_input), # first argument is now a string 
     "%Y/%m/%d %H:%M:%S.%f", 
) 
+0

我已經嘗試過你的解決方案,但它給了我另一個錯誤AttributeError:'method_descriptor'對象沒有屬性'strptime' –

+0

感謝您的幫助,它正在工作nowBelow是更正的代碼selected_time = datetime.strptime('%s %s'%(current_date,time_input),「%Y /%m /%d%H:%M:%S」) –

相關問題