How to create a DateTime equal to 15 minutes ago?

后端 未结 9 1053
庸人自扰
庸人自扰 2020-12-01 05:56

I need to create a DateTime object that represents the current time minus 15 minutes.

9条回答
  •  天涯浪人
    2020-12-01 06:23

    This is simply what to do:

    datetime.datetime.now() - datetime.timedelta(minutes = 15)
    

    timedeltas are specifically designed to allow you to subtract or add deltas (differences) to datetimes.

提交回复
热议问题