Python获取前几周的每周起止日期

一年中,前几月中,前几周中的每周起止时间

-- coding: utf-8 --

import datetime
import time
from datetime import timedelta
current = datetime.datetime.now()

最近两个月的每周起止时间

当前周前m周到后n周的每周开始日期和结束日期

def every_weeks():
m = -8
n = 0
# 当前日期
now = datetime.datetime.now().date()
period_list = []
for x in range(m, n + 1):
if x < 0:
lDay = now - timedelta(days=now.weekday() + (7 * abs(x)))
# 本周
elif x == 0:
lDay = now - timedelta(days=now.weekday())
# 后几周
else:
lDay = now + timedelta(days=(7 - now.weekday()) + 7 * (x - 1))
rDay = lDay + timedelta(days=6)

    start_time = time.strptime(str(lDay), "%Y-%m-%d")
    start_time = int(time.mktime(start_time))
    end_time = time.strptime(str(rDay), "%Y-%m-%d")
    end_time = int(time.mktime(end_time))
    period = [start_time, end_time]
    print [str(lDay), str(rDay)]
    period_list.append(period)
print period_list
return period_list

if name == “main”:
every_weeks()

abs() 返回这个函数的绝对值
初级火:程序员和网络管理员
中级:软件设计师、网络工程师、系统集成项目管理工程师是比较多人报考的
高级:信息系统项目管理师

你可能感兴趣的:(python)