Answer the question
In order to leave comments, you need to log in
How to get number of days from timesamp?
Hello everyone, I'm looking for your help, I can not find it anywhere. We need a script that will output the elapsed number of days from a timesamp value . Thank you.
1 day ago, 2 days ago , 5 days ago , etc.
Answer the question
In order to leave comments, you need to log in
function getDays(timestamp){
var days = Math.floor((Date.now() - timestamp)/(1000*60*60*24));
if(days % 10 == 1)
days += " день назад";
else if(days % 10 == 2 || days % 10 == 3 || days % 10 == 4)
days += " дня назад";
else
days += " дней назад";
return days;
}
alert(getDays(Date.now() - 1000*60*60*24*21));//21 день назад
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question