P
P
ProGad2021-05-10 16:48:04
Python
ProGad, 2021-05-10 16:48:04

How to compare time in python?

Hello qna! I have a virtual economy bot. There is a !work command. I am writing the time to a file. Then I need to compare the time. For a difference of 10 minutes or more.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MinTnt, 2021-05-10
@ProGad

Depends on what format you are recording in?
If the recorded time means time.time()
Then the condition for checking can be done like this:

#Допустим K это время что сохраненно в файле
if (time.time()-K) > 60 * 10:

I
Ivan Yakushenko, 2021-05-10
@kshnkvn

from datetime import datetime

date_x = datetime.fromtimestamp(1620471076) # твоя изначальная дата
date_y = datetime.now()

diff = (date_y - date_x).total_seconds()

There are 60 seconds in 1 minute.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question