时间模块之预约时.py 544 B

12345678910111213141516171819
  1. # -*- coding: UTF-8 -*-
  2. import datetime
  3. inp = input('输入时间格式(年-月-日 时:分:秒):')
  4. nowtime = datetime.datetime.now()
  5. # restime = datetime.datetime.strptime(inp, '%Y-%m-%d %H:%M:%S')
  6. restime = datetime.datetime.strptime("2020-09-23 12:00:00", '%Y-%m-%d %H:%M:%S')
  7. # print (nowtime)
  8. # print(restime)
  9. t = restime - nowtime
  10. print(str(t))
  11. print(t.days)
  12. print(t.seconds)
  13. hour, second = divmod(t.seconds, 3600)
  14. minute, second = divmod(second, 60)
  15. data_time = f"{t.days}天{hour}小时{minute}分{second}秒"
  16. print(data_time)