Python 作为日期对象的月份天数
如何为特定月份和年份中的每一天生成Python 作为日期对象的月份天数,python,date,Python,Date,如何为特定月份和年份中的每一天生成日期对象的列表 我尝试过使用日历模块,但这不是我想要的。使用timedelta模块,您可以很好地循环所有可能的值,并在月份发生变化时停止 from datetime import date, timedelta def generate_month_days(year, month): start_date = date(year, month, 01) cur_date = start_date while cur_date.mon
日期对象的列表
我尝试过使用日历
模块,但这不是我想要的。使用timedelta模块,您可以很好地循环所有可能的值,并在月份发生变化时停止
from datetime import date, timedelta
def generate_month_days(year, month):
start_date = date(year, month, 01)
cur_date = start_date
while cur_date.month == start_date.month:
yield cur_date
cur_date += timedelta(days=1)
for d in generate_month_days(2015,11):
print d