我是靠谱客的博主 谦让短靴,这篇文章主要介绍python获取指定年份的所有日期,现在分享给大家,希望可以做个参考。

def all_year(year):

    cont =[]
    
    if (year % 4) == 0:
       if (year % 100) == 0:
           if (year % 400) == 0:
               #print("{0} 是闰年".format(year))   # 整百年能被400整除的是闰年
               n = 29
           else:
               #print("{0} 不是闰年".format(year))
               n = 28
       else:
           #print("{0} 是闰年".format(year))       # 非整百年能被4整除的为闰年
           n = 29
    else:
       #print("{0} 不是闰年".format(year))
       n = 28

    for i in range(1,13):
        if i==2:
            t = n
        elif i in [4,6,9,11]:
            t = 30
        else:
            t = 31

        if i<10:
            yy =  '0'+str(i)
        else:
            yy = str(i)

        for e in range(1,t+1):

            if e<10:
                y = '0'+str(e)
            else:
                y = str(e)

            r = str(year)+'-'+yy+'-'+y
            cont.append(r)
    print(len(cont))
    return cont

最后

以上就是谦让短靴最近收集整理的关于python获取指定年份的所有日期的全部内容,更多相关python获取指定年份内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(160)

评论列表共有 0 条评论

立即
投稿
返回
顶部