注意需要python3

1、距离某一特定日期多少天后,如 100天

from datetime import datetime,timedelta
pre=datetime(2016,12,12,22,30,50,55) # 年月日时分秒 微秒
dst=pre+timedelta(days=100)#timedelta([days[, seconds[, microseconds[, milliseconds[, minutes[, hours[, weeks]]]]]]])
print(dst)

 2、现在距离某一天多久了

from datetime import datetime,timedelta
pre=datetime(2016,12,12,22,30,50,55) # 年月日时分秒 微秒
now=datetime.now()
dst=now-pre
print(dst)

 3、两个时间差

from datetime import datetime,timedelta
pre=datetime(2016,12,12,22,30,50,55) # 年月日时分秒 微秒
pre2=datetime(2016,12,13,22,30,50,55) # 年月日时分秒 微秒
dst=pre2-pre
print(dst)

 

相关文章:

  • 2021-09-10
  • 2021-12-02
  • 2022-12-23
  • 2021-07-15
  • 2021-04-07
  • 2022-03-08
  • 2022-01-22
  • 2022-12-23
猜你喜欢
  • 2021-10-20
  • 2022-12-23
  • 2021-09-01
  • 2021-04-17
  • 2021-06-26
  • 2022-01-01
  • 2021-10-18
相关资源
相似解决方案