[英]Python calendar, counting empty days of the week before the first of the month
I did something like this:我做了这样的事情:
import datetime
nb_blank_days = (int(datetime.date(year, month, 1).strftime('%w'))+6)%7
But I doesn't looks very pythonic.但我看起来不是很pythonic。 Any help?
有什么帮助吗?
The goal is to say that because the first of July is a friday, there is 4 blanks in the week before displaying the first.目标是说因为 7 月 1 日是星期五,所以在显示第一个之前的一周有 4 个空白。
How about just刚刚怎么样
datetime.date(year, month, 1).weekday()
Since 0
is Monday, I think this does what you want.由于
0
是星期一,我认为这可以满足您的要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.