【问题标题】:Python calendar, counting empty days of the week before the first of the monthPython日历,计算月初前一周的空天
【发布时间】:2011-07-06 14:38:16
【问题描述】:

我做了这样的事情:

import datetime
nb_blank_days = (int(datetime.date(year, month, 1).strftime('%w'))+6)%7

但我看起来不是很pythonic。有什么帮助吗?

目标是说因为 7 月 1 日是星期五,所以在显示第一个之前的一周有 4 个空白。

【问题讨论】:

    标签: datetime date python strftime


    【解决方案1】:

    怎么样

    datetime.date(year, month, 1).weekday()
    

    由于0 是星期一,我想这就是你想要的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-05
      • 1970-01-01
      • 1970-01-01
      • 2011-04-06
      • 2015-10-07
      • 1970-01-01
      相关资源
      最近更新 更多