仅工作几天时,“ datetime.timedelta”和“ dateutil.relativedelta.relativedelta”有什么区别?
datetime.timedelta(来自Python的标准库)和dateutil.relativedelta.relativedelta仅工作几天有什么区别? 据我了解,timedelta仅支持几天(和几周),而relativedelta增加了对根据年,月,周或天定义的时间段以及为年,月或天定义的绝对值的支持。(请记住,出于这个问题的目的,我不必担心小时,分钟或秒) 考虑到我只能用工作datetime.date对象,只关心用的天数定义的时间段,有什么之间的区别timedelta和relativedelta?有什么区别吗? from datetime import date, timedelta from dateutil.relativedelta import relativedelta i = -1 # This could have been any integer, positive or negative someday = date.today() # Is there any difference between these two lines? otherday = someday + timedelta(days=i) otherday = someday + relativedelta(days=i)