惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
腾讯CDC
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
LINUX DO - 热门话题
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Project Zero
Project Zero
V
Vulnerabilities – Threatpost
Cisco Talos Blog
Cisco Talos Blog
P
Palo Alto Networks Blog
C
Cisco Blogs
A
Arctic Wolf
月光博客
月光博客
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
量子位
小众软件
小众软件
Latest news
Latest news
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
Security Latest
Security Latest
N
Netflix TechBlog - Medium
K
Kaspersky official blog
人人都是产品经理
人人都是产品经理
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
Y
Y Combinator Blog
P
Proofpoint News Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
M
MIT News - Artificial intelligence
T
Threat Research - Cisco Blogs
S
Schneier on Security
D
Docker
Scott Helme
Scott Helme
MyScale Blog
MyScale Blog
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
GbyAI
GbyAI
有赞技术团队
有赞技术团队
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
H
Help Net Security
Simon Willison's Weblog
Simon Willison's Weblog
J
Java Code Geeks
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tenable Blog
B
Blog
Know Your Adversary
Know Your Adversary
IT之家
IT之家

博客园 - 小墨的童鞋

git操作中出现Unlink of file '......' failed. Should I try again? IDEA建立Spring MVC Hello World 详细入门教程 IDEA手工添加webapp目录 解决错误:Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package. IDEA编译时出现 Information:java: javacTask: 源发行版 1.8 需要目标发行版 1.8 发票打印不全不完整的解决方案(Win10) Idea checkstyle插件的使用 .Net转Java.08.format 修复恢复"可疑"的SQLServer数据库 .Net转Java.07.IDEA和VS常用操作、快捷键对照表 .Net转Java.06.字符串的split的区别 .Net转Java.05.为啥MySQL没有nolock .Net转Java.04.踩到switch的坑 .Net转Java.03.受查异常和非受查异常 通过IntelliJ IDEA和Maven命令查看某个jar包是怎么引入的 .Net转Java.02.数据类型 .Net转Java.01.从Main(main)函数说起 IDEA下Maven的Offline Mode 修改Arduino IDE默认字体
python计算月份的加减
小墨的童鞋 · 2021-06-22 · via 博客园 - 小墨的童鞋

当然可以pip install python-dateutil

但是服务器上我没法安装其他的包,所以手工写了一个

如果是遇到小月的31号,自动调整到30日,2月份相似处理

如果跨年,年份加1

def add_months(start, months):
    year = start.year + months // 12
    month = (start.month + months % 12) % 12
    if month == 0:
        month = 12
    day = start.day
    max_day = calendar.monthrange(year, month)[1]  # 获取某个月最多多少天
    if day > max_day:
        day = max_day
    return datetime.datetime(year, month, day, hour=start.hour, minute=start.minute, second=start.second,
                             microsecond=start.microsecond)