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

参数可选、默认值都为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

 

相关文章:

  • 2021-12-24
  • 2021-11-14
  • 2022-02-13
  • 2022-12-23
  • 2021-11-26
猜你喜欢
  • 2022-12-23
  • 2021-05-29
  • 2022-12-23
  • 2021-05-23
  • 2022-12-23
  • 2021-05-24
  • 2022-12-23
相关资源
相似解决方案