Python implementation obtains the week number of a month and the week number of python.
After searching for half a day, I couldn't find it. How to obtain the date of a month in the datetime processing of Python is the week of this month.
However, I asked for help and wrote a module for me. [If you know that Python has this native library, please do not hesitate to inform me]
I will record it later.
Copy codeThe Code is as follows:
#! /Usr/bin/env python
#-*-Coding: UTF-8 -*-
_ Author _ = '####'
Import datetime
Def get_week_of_month (year, month, day ):
"""
Obtain the week number of a specified day in a month.
Monday as the beginning of a week
"""
End = int (datetime. datetime (year, month, day). strftime ("% W "))
Begin = int (datetime. datetime (year, month, 1). strftime ("% W "))
Return end-begin + 1
If _ name _ = '_ main __':
Print get_week_of_month (2015, 1, 4)
Print get_week_of_month (2015, 1, 5)
Print get_week_of_month (2015, 1, 15)
Print get_week_of_month (2015, 1, 18)