如何只打印工作日的日期(而不是周末),按日期打印几天范围内几个月的日期?

我需要在python中弄清楚如何(在pesudo中)


x = month-begin

y = month-end


for range in (x through y) 

  print(dates of weekdays - Monday trough Friday)


皈依舞
浏览 116回答 2
2回答

HUX布斯

使用date.weekday()。遵循您的伪代码示例:for day in range (x through y)    if day.weekday() in range(0,5):        print(day)

蝴蝶不菲

使用datetime模块:import datetimecurrent=datetime.datetime(2018,8,14,14,00)&nbsp;&nbsp;end=datetime.datetime(2018,12,1,14,00)&nbsp;while current<end:&nbsp; &nbsp; current+=datetime.timedelta(days=1)&nbsp; &nbsp; if current.weekday()<5:&nbsp; &nbsp; &nbsp; &nbsp; print(current.strftime("%-m/%-d"))
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python