我正在尝试创建一个文件日期比较例程。我怀疑以下是一种相当笨拙的方法。
我很难找到有关 timedelta 的属性或方法的信息,或者它们被称为什么的信息;因此,我仅根据天、分和秒来测量下面的日期时间差,并且没有代表年份的列表项。
任何有关替代方案的建议,将不胜感激。
import os
import datetime
from datetime import datetime
import sys
def datetime_filedif(filepath1e, filepath2e):
filelpath1 = str(filepath1e)
filepath1 = str(filepath1e)
filepath2 = str(filepath2e)
filepath1_lmdate = datetime.fromtimestamp(os.path.getmtime(filepath1))
filepath2_lmdate = datetime.fromtimestamp(os.path.getmtime(filepath2))
td_files = filepath2_lmdate - filepath1_lmdate #Time delta of the 2 filedates
td_list = [('td_files.days', td_files.days), ('td_hrs', int(str(td_files.seconds))/3600), ('td_minutes', (int(str(td_files.seconds))%3600)/60), ('td_seconds', (int(str(td_files.seconds))%3600)%60)]
print "Line 25: ", str(td_list)
return td_list