吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1273|回复: 1
收起左侧

[Python 转载] 计算2020-06,2021-08类似的日期之间缺少的月份

[复制链接]
lideshan 发表于 2022-6-2 14:01
# 计算a,b之间缺少的月份
def get_month_list(a, b):
    a_list = a.split('-')
    b_list = b.split('-')
    a_year = int(a_list[0])
    a_month = int(a_list[1])
    b_year = int(b_list[0])
    b_month = int(b_list[1])
    month_list = []
    for i in range(a_year, b_year + 1):
        for j in range(1, 13):
            if i == a_year and j < a_month:
                continue
            if i == b_year and j > b_month:
                continue
            month_list.append(str(i) + '-' + str(j))
    return month_list[1:-1]

a = "2020-06"
b = "2021-08"
print(get_month_list(a, b))

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

yongqiangipone 发表于 2022-6-2 14:16
datautil.rrule(rrule.MONTHLY, dtstart = date1, until = date2).count()  

导入 rrule
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-6-1 07:37

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表