1、获取上月月份截图及脚本
def After_month(): #获取上月月份
now_time = datetime.datetime.now() # 获取当前日期
end_day_in_mouth = now_time.replace(day=1) # 获取本月的第一天
next_mouth = end_day_in_mouth - datetime.timedelta(days=1) # 获取上月的最后一天
return next_mouth.month # 返回上月的月份
After_month = After_month() #调用函数,获取上月月份
2、获取上月年份截图及脚本
def After_year(now_month): #获取上月年份
if now_month == 1:
After_year = now_year - 1
else:
After_year = now_year
return(After_year) # 返回上月年份
After_year = After_year(now_month) #调用函数,获取上月年份
3、获取月份总天数
Month_Range = calendar.monthrange(After_year,After_month)[1] #获取上月总天数
print('获取上月{}月总天数为:{}天'.format(After_month,Month_Range))