在嘗試運行這段代碼我得到Debian的一個錯誤,但它適用於Windows。日期時間工作在Windows,但不是Debian的
def checkTime():
while True:
with open('date.txt') as tar:
target = tar.read()
current = str(datetime.strptime(str(date.today()),'%Y-%m-%d'))[:-9]
if datetime.strptime(current, '%Y-%m-%d') >= datetime.strptime(target, '%Y-%m-%d'):
doSomething()
sleep(10)
它給我這個錯誤:
File "/usr/lib/python2.6/_strptime.py", line 328, in _strptime
data_string[found.end():])
ValueError: unconverted data remains:
date.txt包含:
2013-03-21
兩個系統有完全相同的日期和時間設置。
你爲什麼將今天的日期爲一個字符串,然後再次將其轉換爲datetime,然後將其再次轉換爲字符串再次,只有將其轉換爲datetime對象? – 2013-03-21 10:07:55
科學!或者更現實的解釋是,我傾向於使事情複雜化。 – Leinad177 2013-03-21 12:40:13