检查创建的日期时间并与今天的日期进行比较?(Checking the created time for the date and comparing to todays date?)
我对此并不是很了解,我正在尝试检查文件的创建时间,只是将日期(只有日,月和年)与今天的日期(再次只有日,月和年)进行比较
import os.path, time import datetime fulldate = time.ctime(os.path.getctime("file.xlsx"))有谁知道如何转换日期,然后检查今天的日期?
I've not got very far with this, I'm trying to check the creation time of a file and simply compare the date (only the day, month and year) with todays date (again only day, month and year)
import os.path, time import datetime fulldate = time.ctime(os.path.getctime("file.xlsx"))Anyone know how I can convert the date and then check against todays date?
最满意答案
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" 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"更多推荐
发布评论