def knn_12(): """ 最近12个月 如果想要指定月份 只要修改cur_month参数即可 """ month_list = [] now_time = datetime.datetime.now() year = now_time.year # 当前年份 year_last = now_time.year - 1 # 去年年份 cur_month = now_time.month # 当前月份 for year in [year_last,year]: for month in range(1,13): month_list.append(str(year)+ "-" + str(month)) return month_list[cur_month - 1:cur_month + 11]
标签:12,cur,随笔,Python,time,month,year,now From: https://www.cnblogs.com/wanghong1994/p/16917474.html