Mar*_*kin 5 python comparison timedelta
我正在尝试创建一个提交比较例程.我怀疑以下是一种相当笨重的方法.
我很难找到关于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
Run Code Online (Sandbox Code Playgroud)
ida*_*alz 10
已经有一个解决方案:
import os
modified_time = os.stat(path).st_mtime # time of most recent content modification
diff_time = os.stat(path_1).st_mtime - os.stat(path_2).st_mtime
Run Code Online (Sandbox Code Playgroud)
现在你有时间在Epoch之后的几秒钟内.你为什么要创建一个新的表示,你可以创建一个deltatime或其他什么,为什么要发明一个新的格式?