Answer the question
In order to leave comments, you need to log in
How to calculate the time difference of a post with the current date?
I have this record in my database
indOne({_id: 1})
{
"_id" : 1,
"title" : "hello",
"last_modified" : Timestamp(1538452199, 1),
}
query = {
timestamp: { // 18 minutes ago (from now)
$gt: new Date(ISODate().getTime() - 1000 * 60 * 18)
}
}
Answer the question
In order to leave comments, you need to log in
So, listen. A little explanation. I think you yourself understand that this time is in seconds, reporting from some time immemorial (like since 2000). You take this time and compare it with yours. You get something like this.
import time
lasttime = "тут берешь время которое выплюнул сервер"
nowtime = time.time()
razniza = int(nowtime) - int(lasttime) # получиться разница в секундах
print(razniza)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question