当前位置:首页 > 日记本 > 正文内容

python 本周、上周、上上周、上上周 代码示例

zhangchap2年前 (2022-04-11)日记本135
# -*- coding:utf-8 -*-
import datetime
from datetime import timedelta
now = datetime.datetime.now().date()

this_week_start = now - timedelta(days=now.weekday())
this_week_end = now + timedelta(days=6 - now.weekday())
print('--- this_week_start = {} this_week_end = {}'.format(this_week_start, this_week_end))

last_week_start = (now - timedelta(days=now.weekday() + 7))
last_week_end = (now - timedelta(days=now.weekday() + 1))
print('--- last_week_start = {} last_week_end = {}'.format(last_week_start, last_week_end))


llast_week_start = (now - timedelta(days=now.weekday() + 14))
llast_week_end = (now - timedelta(days=now.weekday() + 8))
print('--- llast_week_start = {} llast_week_end = {}'.format(llast_week_start, llast_week_end))

lllast_week_start = (now - timedelta(days=now.weekday() + 21))
lllast_week_end = (now - timedelta(days=now.weekday() + 15))
print('--- lllast_week_start = {} lllast_week_end = {}'.format(lllast_week_start, lllast_week_end))


分享给朋友:

相关文章

网络编辑工具箱注册ComCtl32.ocx

1.把ComCtl32.ocx放到c:\Windows\SysWOW64,注:需要管理员权限 2.打开C:\Windows\System32 找到 cmd.exe 鼠标右键管理员身份...

宝塔重启服务器后,Redis就启动不了解决方案

宝塔重启服务器后,Redis就启动不了解决方案

1.更改权限 chown -R redis.redis /www/server/redis/ 2.设置持久化...

python 发布文章 随机分类(choice)

from random import choice catid = choice([5,6]) #choice 函数从列表中随机提取...

python fake_useragent 模块用法

我们每次发送requests请求时通过random从中随机获取一个随机UserAgent,两行代码即可完成UserAgent的不停更换 from fake_useragent i...

Python 正则表达式 带分组的替换 \g

import re re.sub(r'([^a-z]*)[a-z]([^a-z]*)', '\g<1>\g<2>',wor...

python提高运行速度numba.jit

使用numba.jit。 numba可以将 Python 函数 JIT 编译为机器码执行,大大提高代码运行速度。import time def computeSum(size:&...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。