https://www.cnblogs.com/wanghouxuan/p/7802947.html

 

该函数表示两个时间的间隔

参数可选、默认值都为0:datetime.timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)

比如要输出当前时间一小时之后的时间:

#coding:utf-8
from datetime import datetime,timedelta

time1 = datetime.now()

print time1
print time1.strftime("%y-%m-%d %H:%M:%S")
print (time1+timedelta(hours =1)).strftime("%y-%m-%d %H:%M:%S")

 结果:

时间加一天,一个小时得到新的时间
    




Python datetime之timedelta

相关文章:

  • 2022-12-23
  • 2021-06-18
  • 2021-12-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-26
  • 2021-08-13
  • 2021-12-20
相关资源
相似解决方案