复制代码 代码如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = '####'
import datetime
def get_week_of_month(year, month, day):
"""
获取指定的某天是某个月中的第几周
周一作为一周的开始
"""
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)