Python gets the time and date today, tomorrow, yesterday and the day before yesterday

Install datedays :

pip install datedays

Code:

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

result:

Insert image description here

Click to jump to see more methods –》

Guess you like

Origin blog.csdn.net/qq_33613696/article/details/126372210