python - Week number of the month

后端 未结 14 1450
忘掉有多难
忘掉有多难 2020-12-01 08:11

Does python offer a way to easily get the current week of the month (1:4) ?

14条回答
  •  醉话见心
    2020-12-01 08:40

    def week_of_month(date_value):
     return (date_value.isocalendar()[1] - date_value.replace(day=1).isocalendar()[1] + 1)
    

    date_value should in timestamp format This will give the perfect answer in all the cases

提交回复
热议问题