python获取时间日期今天明天昨天前天

安装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))

结果:

QQ图片20220818143801.png

点击跳转查看更多方法--》GitHub

你可能感兴趣的:(python获取时间日期今天明天昨天前天)