year =[2022,2023]
month = [10,11,12]
all_month = []
for i in year:
for j in month:
begin_of_month = str(datetime.date(i, j, 1).strftime("%Y%m%d"))
_, day = calendar.monthrange(i, j)
end_of_month = str(datetime.date(i, j, day).strftime("%Y%m%d"))
all_month.extend(list(pd.date_range(start=begin_of_month,end=end_of_month,freq='D')))
#####################打印结果
import pandas as pd
pd.set_option('display.max_rows', None) #显示全部行
print(pd.Series(all_month))
备注:上述代码是形成2022年10月、2022年11月、2022年12月、2023年10月、2023年11月、2023年12月,一共6个月的时间,可以根据需求设置不同的年份和月份