[英]How to print dates of weekdays only (not weekends) for a range of days by date, for a range of months?
I need to figure out in python how to (in pesudo) 我需要在python中弄清楚如何(在pesudo中)
x = month-begin
y = month-end
for range in (x through y)
print(dates of weekdays - Monday trough Friday)
Use date.weekday(). 使用date.weekday()。 Following your pseudo-code example: 按照您的伪代码示例:
for day in range (x through y)
if day.weekday() in range(0,5):
print(day)
Use the datetime module: 使用datetime模块:
import datetime
current=datetime.datetime(2018,8,14,14,00)
end=datetime.datetime(2018,12,1,14,00)
while current<end:
current+=datetime.timedelta(days=1)
if current.weekday()<5:
print(current.strftime("%-m/%-d"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.