def month_offset(the_year, the_month, offset_month):
"""
:param offset_month: 负数为以前,整数为以后
"""
month = datetime.datetime.strptime(str(the_year) + str(the_month), '%Y%m') + relativedelta(months=offset_month)
month = month.month
if offset_month < 0 and abs(month) > the_month:
year = the_year - 1
elif offset_month > 0 and the_month > month:
year = the_year + 1
else:
year = the_year
return datetime.datetime.strptime(str(year) + str(month), '%Y%m')
获取月偏移值
最新推荐文章于 2024-03-27 14:39:19 发布