0
我對此沒有太多瞭解,我試圖檢查一個文件的創建時間,並簡單地將日期(僅日,月和年)與今天的日期(同樣只是日,月和年)檢查日期的創建時間並與今天的日期進行比較?
import os.path, time
import datetime
fulldate = time.ctime(os.path.getctime("file.xlsx"))
任何人都知道我怎麼能轉換日期,然後覈對當天的日期?
我對此沒有太多瞭解,我試圖檢查一個文件的創建時間,並簡單地將日期(僅日,月和年)與今天的日期(同樣只是日,月和年)檢查日期的創建時間並與今天的日期進行比較?
import os.path, time
import datetime
fulldate = time.ctime(os.path.getctime("file.xlsx"))
任何人都知道我怎麼能轉換日期,然後覈對當天的日期?
import os.path, time
from datetime import datetime
from time import mktime
fulldate = time.ctime(os.path.getctime("file.xlsx"))
struct = time.strptime(fulldate)
filetime = datetime.fromtimestamp(mktime(struct))
filedate = filetime.replace(hour=0, minute=0, second=0, microsecond=0)
if filetime < datetime.now():
print "The file is quite old"
else:
print "The file is not so old"
這是相當多了,這不是很爲我工作但是它非常接近,我可以通過選擇前10個字符來修復它,但基本上我不需要比較文件的時間,只是日期 – Ryflex
見http://stackoverflow.com/questions/237079/how-to-get-file-creation-modification-date-times-in-python – joel3000