安装datedays:

pip install datedays

代码:

import datedays

if __name__ == '__main__':
    print("现在时间:", datedays.getnow()) 		 # format_=格式,比如:%Y-%m-%d %H:%M:%S
    print('-' * 30)
    print("明天:", datedays.gettomorrow())
    print("后天:", datedays.gettomorrow(days=2))  # days等于多少,就是多少天
    print("30天后是几号:", datedays.gettomorrow(days=30))
    print("180天后是几月几号:", datedays.gettomorrow(days=180))
    print("1000天后是几月几号:", datedays.gettomorrow(days=1000))
    print('-' * 30)
    print("昨天:", datedays.getyesterday())
    print("前天:", datedays.getyesterday(days=2))
    print("180天前:", datedays.getyesterday(days=180))
    print("1000天前是几月几号:", datedays.getyesterday(days=1000))

结果:

在这里插入图片描述

点击跳转查看更多方法–》

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐