How to create a DateTime equal to 15 minutes ago?

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

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

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 06:33

    If you are using time.time() and wants timestamp as output

    Simply use

    CONSTANT_SECONDS = 900 # time  in seconds (900 seconds = 15 min)
    
    current_time = int(time.time())
    time_before_15_min = current_time - CONSTANT_SECONDS
    

    You can change 900 seconds as per your required time.

提交回复
热议问题