我是編碼新手,無法弄清楚我在哪里破壞。ValueError 不斷出現,但我似乎無法弄清楚我在哪里打破
def sunset(date,daycycle):
sunset_date_time = ''
year = date.strftime("%Y")
year_data = daycycle.get(year)
if(year_data != None):
month_day = date.strftime("%m-%d")
result_set = year_data.get(month_day)
if(result_set != None):
sunset_time = result_set["sunset"]
sunset_date_time = year "-" month_day " " sunset_time
return datetime.datetime.strptime(sunset_date_time, "%Y-%m-%d %H:%M")
uj5u.com熱心網友回復:
這個錯誤是由變數“sunset_date_time”的日期格式引起的
當您嘗試回傳物件時,此變數的日期格式不是“%Y-%m-%d %H:%M”
要查看什么格式,您可以嘗試列印此值或從函式回傳并檢查年、月、日、小時和分鐘的順序
定義日落(日期,日周期):
sunset_date_time = ''
year = date.strftime("%Y")
year_data = daycycle.get(year)
if(year_data != None):
month_day = date.strftime("%m-%d")
result_set = year_data.get(month_day)
if(result_set != None):
sunset_time = result_set["sunset"]
sunset_date_time = year "-" month_day " " sunset_time
print(sunset_date_time)
"""
or return sunset_date_time
"""
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/390739.html
上一篇:合并日期和時間,找出R中的時差
